So I was developing a project using mongo and I got an error after executing the code:
db.usercollection.insert({ "username" : "testuser1", "email" : "[email protected]" })
The error displayed was:
Cannot use 'commands' readMode, degrading to 'legacy' mode WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on watersheds to execute command { insert: \"usercollection\", documents: [ { _id: ObjectId('568d0eda45d472b121116bef'), username: \"testuser1\", email: \"[email protected]\" } ], ordered: true }"
} })
The db.version() is 3.0.7 and I installed MongoDB shell version is 3.2.0
How should I fix this?
Regards, Daryll
db.getCollection(collectionName).count({});
db.getCollection(collectionName).find({});
It works! maybe mongo needs other operation.
I just restart the mongod process instead and works for me.
Expanding on @Buzut's comment above...
I just ran into this same error. For me, the issue was a version difference between the client running locally and the version of the mongo db running in the cloud.
To verify if that's your issue, run mongo --version
locally and take note of the version number. Then connect to your mongo db shell and run db.version()
to check the version there.
If there is a major difference in those numbers (like a version 3 client and a version 2 db), you'll likely need to switch to client version that's closer to your db version.
To do that, go the Mongo download center: https://www.mongodb.com/download-center#production
Select your platform, then click on 'All Version Binaries', and look for a download that matches your hosted db.
That will download a compressed file that you'll need to unpack. And inside there will be a folder. Simply use the path to the /bin/mongo executable (inside that folder) to execute your mongo commands. For example:
/path/to/downloads/mongodb-osx-x86_64-2.6.9/bin/mongo <whatever mongo commands you want>
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With