Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB error: Cannot use 'commands' readMode, degrading to 'legacy' mode

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

like image 906
dgnebres Avatar asked Jan 06 '16 13:01

dgnebres


3 Answers

db.getCollection(collectionName).count({});
db.getCollection(collectionName).find({});

It works! maybe mongo needs other operation.

like image 199
Geraint Avatar answered Sep 23 '22 20:09

Geraint


I just restart the mongod process instead and works for me.

like image 41
harryssuperman Avatar answered Sep 22 '22 20:09

harryssuperman


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.

like image 44
Malcolm Diggs Avatar answered Sep 26 '22 20:09

Malcolm Diggs