MacOS Ventura 13.1 Upgrade on Macbook Air M1 - Mongoose Not Connecting

Hello,

I recently upgraded my Macbook Air M1 2020 to Ventura 13.1 OS. Once the software update was finished, my backend would no longer connect to my MongoDB database. I have spent several days trying all ways of debugging without any luck. Hoping maybe someone had the same issue.

This is what my terminal looks like when I try to run my backend

~/Cinderblox/Cinderblox_Backend (main*) » npm start    daenamcclintock@Daenas-MacBook-Air

> cinderblox@1.0.0 start
> node server.js

listening on port 8000
THIS IS THE CONNECTION ERROR MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Connection.openUri (/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/connection.js:825:32)
    at /Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/index.js:409:10
    at promiseOrCallback (/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:11:14)
    at Mongoose._promiseOrCallback (/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/index.js:1262:10)
    at Mongoose.connect (/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/index.js:408:20)
    at Object.<anonymous> (/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/server.js:38:10)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}
/Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:21
              throw error;
              ^

Error: Connect error to MongoDB
    at /Users/daenamcclintock/Cinderblox/Cinderblox_Backend/server.js:43:9
    at /Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:18:13
    at /Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/index.js:411:16
    at /Users/daenamcclintock/Cinderblox/Cinderblox_Backend/node_modules/mongoose/lib/connection.js:843:14
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:533:9)
    at process.processTimers (node:internal/timers:507:7)

Node.js v19.3.0

When I run ‘brew services list’ it shows that my mongodb-community is not connecting.

~/Cinderblox/Cinderblox_Backend (main*) » brew services list                                                                     1 ↵ daenamcclintock@Daenas-MacBook-Air
Name                  Status       User            File
mongodb-community     error  15872 root            ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mongodb-community@4.4 error  12288 daenamcclintock ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@4.4.plist

when I try to connect to Mongosh, I get the error: connect ECONNREFUSED 127.0.0.1:27017

~/Cinderblox/Cinderblox_Backend (main*) » mongosh                               daenamcclintock@Daenas-MacBook-Air
Current Mongosh Log ID:	63b549491509be2622a61dcb
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

I have tried restarting mongodb-community

/ » brew services restart mongodb/brew/mongodb-community      daenamcclintock@Daenas-MacBook-Air
Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)

I also tried upgrading brew and reinstalling mongodb-community, all without luck.

Please let me know if anyone knows how to solve this issue.

Thanks

Your mongod should be up & running to connect to it
Check mongod.log if it is giving more details

This is what is showing in my mongod.log

mongod
{"t":{"$date":"2023-01-05T13:21:54.885+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"thread2","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-01-05T13:21:54.886+08:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"thread2","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2023-01-05T13:21:54.887+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread2","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread2","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread2","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread2","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread2","msg":"Multi threading initialized"}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":94432,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"Daenas-MacBook-Air.local"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"CONTROL",  "id":23352,   "ctx":"initandlisten","msg":"Unable to resolve sysctl {sysctlName} (number) ","attr":{"sysctlName":"hw.cpufrequency"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"CONTROL",  "id":23351,   "ctx":"initandlisten","msg":"{sysctlName} unavailable","attr":{"sysctlName":"machdep.cpu.features"}}
{"t":{"$date":"2023-01-05T13:21:54.889+08:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.3","gitVersion":"f803681c3ae19817d31958965850193de067c516","modules":[],"allocator":"system","environment":{"distarch":"aarch64","target_arch":"aarch64"}}}}
{"t":{"$date":"2023-01-05T13:21:54.890+08:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.2.0"}}}
{"t":{"$date":"2023-01-05T13:21:54.890+08:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2023-01-05T13:21:54.891+08:00"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"E",  "c":"CONTROL",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":15000}}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"REPL",     "id":4794602, "ctx":"initandlisten","msg":"Attempting to enter quiesce mode"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"-",        "id":6371601, "ctx":"initandlisten","msg":"Shutting down the FLE Crud thread pool"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"CONTROL",  "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2023-01-05T13:21:54.892+08:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"MigrationUtil-TaskExecutor","msg":"Killing all outstanding egress activity."}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"COMMAND",  "id":4784923, "ctx":"initandlisten","msg":"Shutting down the ServiceEntryPoint"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":4784928, "ctx":"initandlisten","msg":"Shutting down the TTL monitor"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":6278511, "ctx":"initandlisten","msg":"Shutting down the Change Stream Expired Pre-images Remover"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2023-01-05T13:21:54.893+08:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

It is saying invalid dbpath directory
How did you try to start your mongod?
If you just issued mongod it will try to start on default directory /data/db
On Macos access to root folder is removed
So you have to give another valud path where mongod can write
If mongod is started with a config file check dbpath location and try to give a valid path
Also search our forum threads.You will get more details

My backend was working fine and connecting to my mongodb database before the OS Ventura 13.1 software update. I have not changed anything other than upgrading my operating system.

I am connecting to mongodb through the following script:

const mongoose = require('mongoose')

const db = 'mongodb://127.0.0.1/cinderblox-backend-test'

mongoose.set('strictQuery', true);
mongoose.connect(db,{
	useNewUrlParser: true,
  },(err) => {
	if(err) {
		console.log("THIS IS THE CONNECTION ERROR", err)
		throw new Error("Connection error to MongoDB");
	}
});

I have searched through the threads and found others with a similar issue, however none of the solutions worked for me.

I tried running ‘brew upgrade’ to upgrade to mongodb-community 6.0.3, but I am still getting the same connect ECONNREFUSED 127.0.0.1:27017 error.

Can you advise any other solutions as to why I am all of a sudden unable to connect to my database ?

There is a thread which shows ver6 will not run on Ventura
What is the error from mongod.log now?
You have to downgrade to lower version

Regarding os upgrade did you check this thread

Stennie clearly mentioned after os upgrade mongod is not allowed to access /data/db in some versions of Macos
If you used brew services to install it will take care of all necessary permissions directory path etc
The reason it worked before is /data/db is accessible in older version but not in your upgraded version

Hi! I’m new to coding too, I ran into a similar problem of suddenly being unable to connect to mongoDB:


I was just able to solve it by running the server again.

Try this, in the terminal go to mongoDB shell with the command mongo or mongosh
Then run the server with the following command:
mongod --dbpath ~/data/db
(with the proper path to the db that is on your machine)