-1
I am running an application Node and mongodb Docker on my machine, but when I try to connect to the bank using moogose returns:
MongoError: Authentication failed.
at MessageStream.messageHandler (D:\Node\08-multi-dbb-mongodb\node_modules\mongodb\lib\cmap\connection.js:272:20)
at MessageStream.emit (events.js:223:5)
at processIncomingData (D:\Node\08-multi-dbb-mongodb\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (D:\Node\08-multi-dbb-mongodb\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at doWrite (_stream_writable.js:435:12)
at writeOrBuffer (_stream_writable.js:419:5)
at MessageStream.Writable.write (_stream_writable.js:309:11)
at Socket.ondata (_stream_readable.js:728:22)
at Socket.emit (events.js:223:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:181:23) {
ok: 0,
code: 18,
codeName: 'AuthenticationFailed',
name: 'MongoError'
}
Follow how I’m making the connection:
file name: mongodb.js
const mongoose = require('mongoose')
mongoose.connect('mongodb://user:password@localhost:27017/dbname',
{useNewUrlParser: true, useUnifiedTopology: true}, function (error){
if(!error) return;
console.log('Falha na conexao!', error)
}
)
const connection = mongoose.connection
connection.once('open', () => console.log('database rodando!!'))
I can access the bank through the client (visual interface) and I can connect to the bank also through the terminal, giving a
docker exec -it 347b053d4320 mongo -u user -p password --authenticationDatabase myDb
But when I try the code running the mongodb.js file, it returns the error.
If you can help me please.
Thank you!