On my Mac,`brew services start mongodb-community@4.2` starts mongod process in unknown port

~ brew services start mongodb-community@4.2             
==> Successfully started `mongodb-community@4.2` (label: homebrew.mxcl.mongodb-community@4.2)

It ran successful. But:

~ mongo                                                   
MongoDB shell version v4.2.21
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2022-08-16T16:25:03.024-0500 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:353:17
@(connect):2:6
2022-08-16T16:25:03.029-0500 F  -        [main] exception: connect failed
2022-08-16T16:25:03.029-0500 E  -        [main] exiting with code 1

And

~ sudo lsof -i :27017

returned nothing.

So this concludes that mongod is running on some unknown PORT.

Share the configuration file and we might help.

Also share the output of

sudo ss -tlp

or

sudo netstat -tlp

The output of the following is also needed:

sudo ps -aef | grep [m]ongo

where do I find the configuration file?

systemLog:
  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /opt/homebrew/var/mongodb
net:
  bindIp: 127.0.0.1, ::1
  ipv6: true

This is what is in my /opt/homebrew/etc/mongod.conf file

ss is not a recognized command.

~ sudo netstat -tlp                 
netstat: option requires an argument -- p
Usage:	netstat [-AaLlnW] [-f address_family | -p protocol]
	netstat [-gilns] [-f address_family]
	netstat -i | -I interface [-w wait] [-abdgRtS]
	netstat -s [-s] [-f address_family | -p protocol] [-w wait]
	netstat -i | -I interface -s [-f address_family | -p protocol]
	netstat -m [-m]
	netstat -r [-Aaln] [-f address_family]
	netstat -rs [-s]
~ sudo ps -aef | grep mongo  
  501  4445   854   0  8:51AM ttys002    0:00.00 grep mongo

The ps output shows that mongod has not been started.

Share the log file.

where is the log file located?

It is specified in the configuration file you shared.

The file is too enormous:

2022-08-15T13:21:43.753-0500 I CONTROL [main] ***** SERVER RESTARTED *****
2022-08-15T13:21:43.759-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’
2022-08-15T13:21:43.762-0500 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] MongoDB starting : pid=85422 port=27017 dbpath=/opt/homebrew/var/mongodb 64-bit host=Junlues-MacBook-Pro.local
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] db version v4.2.21
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] git version: b0aeed9445ff41af07449fa757e1f231bce990b3
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] allocator: system
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] modules: none
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] build environment:
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] distarch: x86_64
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] target_arch: x86_64
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] machdep.cpu.extfeatures unavailable
2022-08-15T13:21:43.763-0500 I CONTROL [initandlisten] options: { config: “/opt/homebrew/etc/mongod.conf”, net: { bindIp: “127.0.0.1, ::1”, ipv6: true }, storage: { dbPath: “/opt/homebrew/var/mongodb” }, systemLog: { destination: “file”, logAppend: true, path: “/opt/homebrew/var/log/mongodb/mongo.log” } }
2022-08-15T13:21:43.764-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2022-08-15T13:21:43.764-0500 I REPL [initandlisten] Stepping down the ReplicationCoordinator for shutdown, waitTime: 10000ms
2022-08-15T13:21:43.765-0500 I SHARDING [initandlisten] Shutting down the WaitForMajorityService
2022-08-15T13:21:43.765-0500 I NETWORK [initandlisten] Shutting down the global connection pool
2022-08-15T13:21:43.765-0500 I INDEX [initandlisten] Shutting down the IndexBuildsCoordinator
2022-08-15T13:21:43.765-0500 I NETWORK [initandlisten] Shutting down the ReplicaSetMonitor
2022-08-15T13:21:43.765-0500 I CONTROL [initandlisten] Shutting down free monitoring
2022-08-15T13:21:43.765-0500 I FTDC [initandlisten] Shutting down full-time data capture
2022-08-15T13:21:43.765-0500 I STORAGE [initandlisten] Shutting down the HealthLog
2022-08-15T13:21:43.765-0500 I - [initandlisten] Dropping the scope cache for shutdown
2022-08-15T13:21:43.765-0500 I CONTROL [initandlisten] now exiting
2022-08-15T13:21:43.765-0500 I CONTROL [initandlisten] shutting down with code:48

Means a process is already using the same address/port combination.

Share the output of

sudo netstat -l
brew services list

~ brew services start mongodb-community@4.2          
==> Successfully started `mongodb-community@4.2` (label: homebrew.mxcl.mongodb-community@4.2)
~ brew services list                       
Name                  Status      User File
mongodb-community@4.2 error  3584 gani ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@4.2.plist
rabbitmq              started     gani ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
redis                 started     gani ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
sudo netstat -l
Proto Recv-Q Send-Q  Local Address                                 Foreign Address                               (state)    
tcp4       0      0  10.0.0.183.49770                              ec2-54-92-199-18.https                        ESTABLISHED
tcp4      31      0  10.0.0.183.49769                              ec2-35-163-77-22.https                        CLOSE_WAIT 
tcp4       0      0  10.0.0.183.49765                              20.189.173.7.https                            ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49764   2001:558:feed:443::12.https                   ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49763   2606:4700:90:0:f22e:fbec:5bed:a9b9.https      ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49759   ord08s13-in-x03.1e100.net.https               ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49755   ord30s22-in-x05.1e100.net.https               ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49753   2001:558:feed:443::12.https                   ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49752   2600:9000:2350:fa00:8:4923:b2c0:21.https      ESTABLISHED
tcp4       0      0  10.0.0.183.49751                              server-65-8-55-1.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49749                              52.46.154.73.https                            ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49744   2a04:4e42:84::272.https                       ESTABLISHED
tcp4       0      0  10.0.0.183.49732                              160.35.184.35.bc.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49696                              ec2-54-217-83-24.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49695                              162.219.225.118.https                         ESTABLISHED
tcp4       0      0  10.0.0.183.49618                              ec2-54-145-94-22.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49617                              ec2-54-145-94-22.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49614                              ec2-54-147-76-65.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49600                              ec2-54-145-94-22.https                        ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49581   2a04:4e42:83::272.https                       ESTABLISHED
tcp4       0      0  10.0.0.183.49475                              stackoverflow.co.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49390                              stackoverflow.co.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49389                              ec2-54-175-191-2.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49385                              ec2-3-214-160-18.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49381                              ec2-34-227-4-145.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49377                              ec2-54-175-191-2.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49376                              stackoverflow.co.https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49364                              stackoverflow.co.https                        ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49359   2600:9000:2350:4400:7:7859:3840:93a1.https    ESTABLISHED
tcp4       0      0  10.0.0.183.49305                              104.192.142.18.https                          ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49301   2606:4700:90:0:f22e:fbec:5bed:a9b9.https      ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49274   ga-in-f188.1e100.net.5228                     ESTABLISHED
tcp4       0      0  localhost.epmd                                localhost.49271                               ESTABLISHED
tcp4       0      0  localhost.49271                               localhost.epmd                                ESTABLISHED
tcp4      24      0  10.0.0.183.49229                              static.59.20.181.https                        CLOSE_WAIT 
tcp4       0      0  10.0.0.183.49216                              ec2-3-225-113-73.https                        ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49201   2001:558:feed:443::12.https                   ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49197   2001:558:feed:443::12.https                   ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49196   2001:558:feed:443::12.https                   ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.49195   2001:558:feed:443::12.https                   ESTABLISHED
tcp4       0      0  10.0.0.183.49178                              ec2-3-215-27-40..https                        ESTABLISHED
tcp4       0      0  10.0.0.183.49152                              ec2-52-44-179-25.https                        ESTABLISHED
tcp4       0      0  localhost.epmd                                localhost.49771                               TIME_WAIT  
tcp4       0      0  localhost.49773                               localhost.epmd                                TIME_WAIT  
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.64362   2620:149:a42:903::e.443                       ESTABLISHED
tcp4       0      0  10.0.0.183.49279                              17.248.190.204.443                            ESTABLISHED
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.64361   2620:149:a42:903::e.443                       TIME_WAIT  
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.64360   2620:149:a42:903::e.443                       TIME_WAIT  
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.64359   2620:149:a42:903::e.443                       TIME_WAIT  
tcp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.63787   2603:1036:304:2853::2.443                     ESTABLISHED
tcp4       0      0  10.0.0.183.65454                              17.57.144.134.5223                            ESTABLISHED
udp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.61814   ord38s33-in-x0e.1e100.net.https                          
udp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.61608   ord37s08-in-x03.1e100.net.https                          
udp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.58947   ord38s29-in-x03.1e100.net.https                          
udp6       0      0  2601:241:8202:54b0:461:1336:75bf:e2af.62043   ord38s28-in-x0a.1e100.net.https                          
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*                                                      
udp4       0      0  *.*                                           *.*       

To solve

Replace

with

logAppend: false

and then redo

Share the log file, we should get the real reason why it fails. The other error from the log you shared is from 2 days ago. Most likely you had another mongod running at that time.

2022-08-17T10:55:27.046-0500 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2022-08-17T10:55:27.048-0500 W  ASIO     [main] No TransportLayer configured during NetworkInterface startup
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] MongoDB starting : pid=30240 port=27017 dbpath=/opt/homebrew/var/mongodb 64-bit host=Junlues-MacBook-Pro.local
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] db version v4.2.21
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] git version: b0aeed9445ff41af07449fa757e1f231bce990b3
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] allocator: system
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] modules: none
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] build environment:
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten]     distarch: x86_64
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten]     target_arch: x86_64
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] machdep.cpu.extfeatures unavailable
2022-08-17T10:55:27.049-0500 I  CONTROL  [initandlisten] options: { config: "/opt/homebrew/etc/mongod.conf", net: { bindIp: "127.0.0.1, ::1", ipv6: true }, storage: { dbPath: "/opt/homebrew/var/mongodb" }, systemLog: { destination: "file", logAppend: false, path: "/opt/homebrew/var/log/mongodb/mongo.log" } }
2022-08-17T10:55:27.050-0500 I  STORAGE  [initandlisten] Detected data files in /opt/homebrew/var/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2022-08-17T10:55:27.050-0500 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=15872M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2022-08-17T10:55:27.166-0500 E  STORAGE  [initandlisten] WiredTiger error (-31802) [1660751727:166653][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error Raw: [1660751727:166653][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.219-0500 E  STORAGE  [initandlisten] WiredTiger error (-31802) [1660751727:219207][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error Raw: [1660751727:219207][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.243-0500 E  STORAGE  [initandlisten] WiredTiger error (-31802) [1660751727:243834][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error Raw: [1660751727:243834][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.278-0500 E  STORAGE  [initandlisten] WiredTiger error (-31802) [1660751727:278461][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error Raw: [1660751727:278461][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.315-0500 E  STORAGE  [initandlisten] WiredTiger error (-31802) [1660751727:315348][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error Raw: [1660751727:315348][30240:0x20969b600], connection: __log_open_verify, 925: unsupported WiredTiger file version: this build only supports versions up to 4, and the file is version 5: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.337-0500 W  STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
2022-08-17T10:55:27.337-0500 F  STORAGE  [initandlisten] Reason: -31802: WT_ERROR: non-specific WiredTiger error
2022-08-17T10:55:27.337-0500 F  -        [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 928
2022-08-17T10:55:27.337-0500 F  -        [initandlisten] \n\n***aborting after fassert() failure\n\n

It looks like you had a more recent version of mongod using the same data directory.

I see 3 ways out:

1 - If the data that is there IS IMPORTANT, install and run a 5.x version rather than 4.2

or

2 - If the data that is there IS IMPORTANT and you MUST run 4.2,

  • make a backup of the data directory for later retrieval
  • create a new directory /opt/homebrew/var/mongodb-4.2
  • change the configuration file to reflect the new dbPath

or

3 - If the data that is there IS NOT IMPORTANT and you must run 4.2

  • make a backup of the data directory for later retrieval just in case the data is more important than you thought
  • rename /opt/homebrew/var/mongodb to /opt/homebrew/var/mongodb-5.x
  • creaet a new directory /opt/homebrew/var/mongodb/
2 Likes

I chose solution 3 and it worked.

But I am not sure what you mean by data directory

1 Like

It means the directory where mongod store the data. In your case:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.