MongoServerError: Authentication failed

I am trying to connect to a MongoDB v4.4.6 in my Meteor v2.13.3 app. I can connect to this db from the mongo shell and “mongodb compass” but not when starting a meteor app. It also works when I start a meteor server on the same machine as the mongodb is on but by using the external IP.

My .bat file to start my meteor server in windows looks like this:

SET MONGO_URL=mongodb://u:p@111.222.333.444:27017/databaseName
meteor run --settings settings.json

Any idea why my meteor app would be refuced connection?

W20231028-18:26:26.139(7)? (STDERR) C:\Users\j\AppData\Local.meteor\packages\promise\0.12.2\npm\node_modules\meteor-promise\promise_server.js:218
W20231028-18:26:26.149(7)? (STDERR) throw error;
W20231028-18:26:26.149(7)? (STDERR) ^
W20231028-18:26:26.149(7)? (STDERR)
W20231028-18:26:26.149(7)? (STDERR) MongoServerError: Authentication failed.
W20231028-18:26:26.150(7)? (STDERR) at Connection.onMessage (C:\Users\j\AppData\Local.meteor\packages\npm-mongo\4.16.0\npm\node_modules\mongodb\lib\cmap\connection.js:231:30)
W20231028-18:26:26.150(7)? (STDERR) at MessageStream. (C:\Users\j\AppData\Local.meteor\packages\npm-mongo\4.16.0\npm\node_modules\mongodb\lib\cmap\connection.js:61:60)
W20231028-18:26:26.150(7)? (STDERR) at MessageStream.emit (events.js:400:28)
W20231028-18:26:26.151(7)? (STDERR) at MessageStream.emit (domain.js:475:12)
W20231028-18:26:26.151(7)? (STDERR) at processIncomingData (C:\Users\j\AppData\Local.meteor\packages\npm-mongo\4.16.0\npm\node_modules\mongodb\lib\cmap\message_stream.js:125:16)
W20231028-18:26:26.151(7)? (STDERR) at MessageStream._write (C:\Users\j\AppData\Local.meteor\packages\npm-mongo\4.16.0\npm\node_modules\mongodb\lib\cmap\message_stream.js:33:9)
W20231028-18:26:26.151(7)? (STDERR) at writeOrBuffer (internal/streams/writable.js:358:12)
W20231028-18:26:26.152(7)? (STDERR) at MessageStream.Writable.write (internal/streams/writable.js:303:10)
W20231028-18:26:26.152(7)? (STDERR) at Socket.ondata (internal/streams/readable.js:731:22)
W20231028-18:26:26.152(7)? (STDERR) at Socket.emit (events.js:400:28)
W20231028-18:26:26.153(7)? (STDERR) at Socket.emit (domain.js:475:12)
W20231028-18:26:26.153(7)? (STDERR) at addChunk (internal/streams/readable.js:293:12)
W20231028-18:26:26.153(7)? (STDERR) at readableAddChunk (internal/streams/readable.js:267:9)
W20231028-18:26:26.153(7)? (STDERR) at Socket.Readable.push (internal/streams/readable.js:206:10)
W20231028-18:26:26.154(7)? (STDERR) at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
W20231028-18:26:26.154(7)? (STDERR) => awaited here:
W20231028-18:26:26.154(7)? (STDERR) at Function.Promise.await (C:\Users\j\AppData\Local.meteor\packages\promise\0.12.2\npm\node_modules\meteor-promise\promise_server.js:56:12)
W20231028-18:26:26.154(7)? (STDERR) at new MongoConnection (packages/mongo/mongo_driver.js:213:11)
W20231028-18:26:26.155(7)? (STDERR) at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:9:16)
W20231028-18:26:26.155(7)? (STDERR) at Object. (packages/mongo/remote_collection_driver.js:66:18)
W20231028-18:26:26.155(7)? (STDERR) at Object.defaultRemoteCollectionDriver (packages\underscore.js:784:19)
W20231028-18:26:26.156(7)? (STDERR) at new Collection (packages/mongo/collection.js:127:40)
W20231028-18:26:26.156(7)? (STDERR) at AccountsServer._initializeCollection (packages/accounts-base/accounts_common.js:98:20)
W20231028-18:26:26.157(7)? (STDERR) at new AccountsCommon (packages/accounts-base/accounts_common.js:46:23)
W20231028-18:26:26.157(7)? (STDERR) at new AccountsServer (packages/accounts-base/accounts_server.js:30:5)
W20231028-18:26:26.157(7)? (STDERR) at packages/accounts-base/server_main.js:7:12
W20231028-18:26:26.157(7)? (STDERR) at module (packages/accounts-base/server_main.js:19:31)
W20231028-18:26:26.157(7)? (STDERR) at fileEvaluate (packages\modules-runtime.js:336:7)
W20231028-18:26:26.158(7)? (STDERR) at Module.require (packages\modules-runtime.js:238:14)
W20231028-18:26:26.158(7)? (STDERR) at require (packages\modules-runtime.js:258:21)
W20231028-18:26:26.159(7)? (STDERR) at C:\Users\j\OneDrive\Documents\dev\app.meteor\local\build\programs\server\packages\accounts-base.js:2219:15
W20231028-18:26:26.159(7)? (STDERR) at C:\Users\j\OneDrive\Documents\dev\app.meteor\local\build\programs\server\packages\accounts-base.js:2226:3 {
W20231028-18:26:26.160(7)? (STDERR) ok: 0,
W20231028-18:26:26.160(7)? (STDERR) code: 18,
W20231028-18:26:26.161(7)? (STDERR) codeName: ‘AuthenticationFailed’,
W20231028-18:26:26.161(7)? (STDERR) connectionGeneration: 0,
W20231028-18:26:26.161(7)? (STDERR) [Symbol(errorLabels)]: Set(2) { ‘HandshakeError’, ‘ResetPool’ }
W20231028-18:26:26.161(7)? (STDERR) }

I guess the solution was to not use special characters in the db users password…

If you use special characters, maybe you would need to urlencode those.