My port is 5000
MongoServerError: bad auth : Authentication failed.
at Connection.onMessage (E:\React\Projects\assignment11\express\node_modules\mongodb\lib\cmap\connection.js:203:30)
at MessageStream. (E:\React\Projects\assignment11\express\node_modules\mongodb\lib\cmap\connection.js:63:60)
at MessageStream.emit (node:events:390:28)
at processIncomingData (E:\React\Projects\assignment11\express\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
at MessageStream._write (E:\React\Projects\assignment11\express\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at MessageStream.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSSocket.emit (node:events:390:28) {
ok: 0,
code: 8000,
codeName: 'AtlasError',
[Symbol(errorLabels)]: Set(0) {}
I tried so many times by changing the username password and also delete and recreate this. But Still, the problem occurs. I don't understand exactly why is this happening. Can anyone help me to tell the exact reason behind this?
Related
I tried to setup and use Mongo Atlas using the setup steps of the section Setting Up the Mongo db database ,in the Mozila Express tutorial that you can find here, then I got authentication error when running the populatedb.js file mentioned in that tutorial:
This script populates some test books, authors, genres and bookinstances to your database. Specified database as argument - e.g.: populatedb mongodb+srv://cooluser:coolpassword#cluster0.a9azn.mongodb.net/local_library?retryWrites=true
MongoDB connection error: MongoError: Authentication failed.
at MessageStream.messageHandler (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:314:20)
at processIncomingData (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at TLSSocket.ondata (_stream_readable.js:718:22)
at TLSSocket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23) {
ok: 0,
code: 18,
codeName: 'AuthenticationFailed',
'$clusterTime': {
clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 11, high_: 1620398123 },
signature: { hash: [Binary], keyId: [Long] }
},
operationTime: Timestamp { _bsontype: 'Timestamp', low_: 11, high_: 1620398123 }
}
(node:12916) UnhandledPromiseRejectionWarning: MongoError: Authentication failed.
at MessageStream.messageHandler (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:314:20)
at processIncomingData (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at TLSSocket.ondata (_stream_readable.js:718:22)
at TLSSocket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
(node:12916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FINAL ERR: MongooseError: Operation `authors.insertOne()` buffering timed out after 10000ms
node populatedb mongodb+srv://notmyfault
okok:%40mongoDB1#cluster1.zbmx1.mongodb.net/local_library?retryWrites=true
This script populates some test books, authors, genres and bookinstances to your database. Specified database as argument - e.g.: populatedb mongodb+srv://cooluser:coolpassword#cluster0.a9azn.mongodb.net/local_library?retryWrites=true
MongoDB connection error: MongoError: Authentication failed.
at MessageStream.messageHandler (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:314:20)
at processIncomingData (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at TLSSocket.ondata (_stream_readable.js:718:22)
at TLSSocket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23) {
ok: 0,
code: 18,
codeName: 'AuthenticationFailed',
'$clusterTime': {
clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1620398181 },
signature: { hash: [Binary], keyId: [Long] }
},
operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1620398181 }
}
(node:12935) UnhandledPromiseRejectionWarning: MongoError: Authentication failed.
at MessageStream.messageHandler (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:314:20)
at processIncomingData (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/pc/Documents/node_express_tutorial/local_library_app_tutorial/express-locallibrary-tutorial/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at TLSSocket.ondata (_stream_readable.js:718:22)
at TLSSocket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
(node:12935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FINAL ERR: MongooseError: Operation `authors.insertOne()` buffering timed out after 10000ms
[1]+ Done node populatedb mongodb+srv://notmyfaultokok:%40mongoDB1#cluster1.zbmx1.mongodb.net/local_library?retryWrites=true
What I did was click on connect button in the created Cluster of the mongoDB Atlas, copy the url for connect to application. Change the passworld field and the database name field to the mongoDB-Atlas password and the name of the created database in the cluster.
So the authentificaiton error I don;t get as I think i put the correct password in the database url and also I check for if the url encoding is correct as well.
Please help
I solve the error now, it is actually that you can create a user and password for a created database. And so I was using the username and password for the Atlas website and not that of the database itself. New that I created a new database and username and password for that database, I could use that database for my app and it worked fine!
But the steps that i used to arrive at the solution is not straigh forward. I actually started looking at how to implement a search engine for the mongoDB database and found a tutorial that ask me to connect via the mongoDB compass. I used the mongoDB compass to connect with the atlas username and password and it didn't work. but then I was like, this can't be possible. Then i removed the password completely and it seems to connect!.
Afterwards, I also tried again the Express tutorial and remove the password but it still give cannot have empty string password error. But then I was like I'm just gonna create a new account. and try it out. When I created the new account and the new database, they actually asked me to create a username and password for the new database! And this is where I found out that you also have a usernam and password for the created database.
I don't know what happen before, maybe it was cause I created the database long time ago and forget that a database uses a username and password as well.
SO it is solved and I'm moving on the 4th part of the tutorial.
I have an app, created in meteor.js but it shouldn't be important i think. I have also mongo cluster on mongo atlas. So far during development i connected to db by connection string without problem from my local machine. However when i created linux machine on DigitalOcean and tried to connect my app using same connection string mongodb+srv://<user>:<password>#xyz.mongodb.net/<dbName>?retryWrites=true&w=majority
I got the following error.
MongoNetworkError: failed to connect to server [xyz.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to xyz.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:440:9)
at Object.onceWrapper (events.js:421:26)
at TLSSocket.emit (events.js:314:20)
at TLSSocket.EventEmitter.emit (domain.js:483:12)
at net.js:675:12
at TCP.done (_tls_wrap.js:568:7)]
at Pool.<anonymous> (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/topologies/server.js:438:11)
at Pool.emit (events.js:314:20)
at Pool.EventEmitter.emit (domain.js:483:12)
at /home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/pool.js:562:14
at /home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/pool.js:1009:9
at callback (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connect.js:75:5)
at /home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connect.js:101:9
at _callback (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:329:7)
at Connection.errorHandler (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:344:7)
at Object.onceWrapper (events.js:421:26)
at Connection.emit (events.js:314:20)
at Connection.EventEmitter.emit (domain.js:483:12)
at TLSSocket.<anonymous> (/home/ubuntu/staging/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:438:12)
at Object.onceWrapper (events.js:421:26)
at TLSSocket.emit (events.js:314:20)
at TLSSocket.EventEmitter.emit (domain.js:483:12)
Do you have any idea of what could be wrong with me server config? I guess it is server config as on other machine same connection string works.
I'm working on a web application with node.js and using Mongodb for database. everything is cool when I run my app in localhost. but when I run it in a shared host it gives an error which looks like its Mongoose connection problem.
here is my code:
const uri = 'mongodb://****:****#iranroboticacademy-bdziw.mongodb.net/test';
mongoose.connect(uri,{ useNewUrlParser: true });
mongoose.connection.once('open', function(){
console.log('DataBase is connected. ');
}).on('error', function(error){
console.log('Connection error:', error);
});
and here is the erro that I get when I run the app in host:
Connection error: { MongoNetworkError: failed to connect to server [iranroboticacademy-shard-00-00-bdziw.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 3.226.212.92:27017]
at Pool.<anonymous> (/home/iranrob1/public_html/node_modules/mongodb/lib/core/topologies/server.js:433:11)
at Pool.emit (events.js:182:13)
at createConnection (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/pool.js:577:14)
at connect (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/pool.js:1021:9)
at makeConnection (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:31:7)
at callback (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:247:5)
at TLSSocket.err (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:276:7)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {} }
(node:6409) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [iranroboticacademy-shard-00-00-bdziw.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 3.226.212.92:27017]
at Pool.<anonymous> (/home/iranrob1/public_html/node_modules/mongodb/lib/core/topologies/server.js:433:11)
at Pool.emit (events.js:182:13)
at createConnection (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/pool.js:577:14)
at connect (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/pool.js:1021:9)
at makeConnection (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:31:7)
at callback (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:247:5)
at TLSSocket.err (/home/iranrob1/public_html/node_modules/mongodb/lib/core/connection/connect.js:276:7)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:6409) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6409) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Sure you can use the free tier of MongoDB Cloud.
It’s actually much easier to mantain than the hosted version as you have visually all under control, automatic backups etc.
https://mongodb.com
I have asked my host provider in a ticket and they said it doesn’t support mongodb. I have written everything with mongodb database in my application and I really can’t change it into other things. I need to use it in this host. Is there anyone who has a solution for this?!
try to use 'connect to your aplication', copy the then change the
I have a database setup on Mlab and I have aconnection string that does work remotely. If I run my node app on docker using my local mongo, everything works as expected, however if I change the configuration and connect to my Mlab mongo, I get the following error:
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/topologies/server.js:564:11)
at emitOne (events.js:116:13)
at Pool.emit (events.js:211:7)
at Connection.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/pool.js:317:12)
at Object.onceWrapper (events.js:317:30)
at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7)
at Socket.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/connection.js:246:50)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
(node:24) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
Apart from handling the error on Node side (which I'm not catching, but that's another problem), how can I connect to an external mongo server form my Docker container?
I've seen this and follow the steps described there but it didn't help me.
Any suggestions?
EDIT
This is a Node app. In my Dockerfile I have the following setting:
ENV DB_HOST=mongodb+srv://<user>:<password>#<mlab>/<db_name>?retryWrites=true
And in my Node app where I have setup the database I have this:
mongoose.connect(process.env.DB_HOST, {useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true});
When I print the above env variable at run time, I get the correct string for the db (running locally everything works fine).
I don't understand why the error shows localhost. This is my first time using Docker. Do I need any additional configuration so my container can talk to an external service?
Error: connection refused: localtunnel.me:37244 (check your firewall settings)
your url is: https://pretty-skun-91.localtunnel.me
/usr/lib/node_modules/localtunnel/bin/client:65
throw err;
^
Error: connection refused: localtunnel.me:37244 (check your firewall settings)
at Socket.<anonymous> (/usr/lib/node_modules/localtunnel/lib/TunnelCluster.js:47:32)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)