Reputation: 165
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
Upvotes: 7
Views: 13875
Reputation: 31
db.getCollection(collectionName).count({});
db.getCollection(collectionName).find({});
It works! maybe mongo needs other operation.
Upvotes: 3
Reputation: 455
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.
Upvotes: 1
Reputation: 1
Cannot use 'commands' readMode
, degrading to legacy mode
,
rs-ds017231:PRIMARY> show dbs
rs-ds017231:PRIMARY> db
rs-ds017231:PRIMARY>db.collection_name.insert({})
It works for me !
Upvotes: -2
Reputation: 788
I don't know if you are a victim of having replica set
and lost Primary db
or not.
If so, recreate the Primary one or use this command before your insertion.
db.getMongo().setSlaveOk();
Upvotes: 0