I noticed interesting behaviour that is at least common for Java MongoClient and Mongosh in combination with MongoDB server/db provided via Atlas MongoDB. It’s related to user deletion/recreation scenario during active session/connection.
It came out that after db user was accidentally deleted and then recreated manually via Atlas MongoDB console our application that is using Spring Mongo driver (effectively MongoClient from org.mongo.db.mongodb-driver-reactivestreams driver) was not able to recover and needed a restart.
It’s also possible to reproduce it using mongosh via following steps:
- Established mongosh session to Atlas Mongo DB where all commands are working fine.
- Removed Mongo DB user used by #1via Atlas console.
- After a while (time needed for Atlas MongoDB config population) mongosh #1 starts returning errors.
- first cmd fails with “cannot find user account after reload”
- every subsequent cmd fails with „user is not allowed to do action [XXX] on [CollectionYYY].
- Recreated the MongoDB user with the same password.
- Mongosh session #1 is still not able to successfully invoke cmds like “find” etc. and is returning the same errors (Atlas MongoDB config population is completed) but the session seems active in the terminal.
- Started another Mongosh session #2 and it can successfully connect to Atlas MongoDB and invoke cmds.
- Mongos session #1 is still not able successfully invoke commands but connection/session is still active.
Is it desired and documented behavior? It seems natural behaviour would be to recover from above scenario when user is recreated or at least drop existing connection/session created via Mongosh or Java MongoClient?