MongoDB Auth doesn't work
Minecodes opened this issue · 7 comments
My server said "Bad auth" on MongoDB, but my password was right and everything other too.
[Ackee] › ✖ fatal MongoServerError: bad auth : Authentication failed.
at MessageStream.messageHandler (/var/www/analytics/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:467:30)
at MessageStream.emit (node:events:390:28)
at processIncomingData (/var/www/analytics/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
at MessageStream._write (/var/www/analytics/node_modules/mongoose/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)
at addChunk (node:internal/streams/readable:315:12)
Maybe there's no way to connect to the MongoDB in the container/environment Ackee is running. There shouldn't be any trouble connecting otherwise.
I'm closing this issue, because I'm not able to reproduce it. Let me know if there's something I can help with.
@Minecodes is your MongoDB running within another docker container? I got the same issue. After tested with some users with write permission on ackee database, I even tried with mongo root account, but it could not authenticate as expected.
@Minecodes I've fixed my issue. Here is short note, may be useful for you or someone who is facing this problem.
- take a look at the connection string you are using, for example
mongodb://USERNAME:PASSWORD@IP:PORT/ackeedb
- ensure that you have added USERNAME to exactly database
ackeedb
with enough permission
In mongodb you can do it as below:
# connect to mongodb cli with admin account, e.g, admin
mongo -u ADMIN_USER
# with docker
docker exec -it CONTAINER mongo -u ADMIN_USER
# switch to ackee db
use ackeedb
# create user
db.createUser({
user: 'USERNAME',
pwd: 'PASSWORD',
roles:[
{
role: 'readWrite',
db: 'ackeedb'
}
]
})
@Minecodes please, verify if your user does have permission to read/write any database at Security tab on MongoDB Atlas. I had the same issue when I started to use Ackee and it was solved changing this configuration,
@carvalholeo it was the right user, because I used it in my MongoDB CLI.