I am using AWS document db v4.0.0. It works fine with my application using MongoDB driver to connect. But when I try to use mongo shell it gives me some errors on basic query:
db.myCollection.find({})
Error: error: {
"ok" : 0,
"code" : 303,
"errmsg" : "Feature not supported: 'causal consistency'",
"operationTime" : Timestamp(1645150705, 1)
}
Does this mean DocumentDB is not compatible with mongo shell?
Your code is missing the actual connection part, but make sure you have the TLS keys placed on the machine.
Your connection string should be something like this:
mongo --ssl host docdb-2020-02-08-14-15-11. cluster.region.docdb.amazonaws.com:27107 --sslCAFile rds-combined-ca-bundle.pem --username demoUser --password
There is actually a really good example/explanation in the official AWS Documentation
Casual consistency isn't supported in DocumentDB. From your mongo shell you can run "db.getMongo().setCausalConsistency(false)" then re-run your find operation.
https://docs.mongodb.com/manual/reference/method/Mongo.setCausalConsistency/
Related
I'm learning MongoDB and trying to use Atlas. I created a remote cluster and tried to connect it using both MongoDB Compass and Studio 3T. However, I noticed that after connecting with Studio 3T, there was an empty database named "test" appearing in the left panel, below "admin" and "local" databases. Where did it come from? And how can I drop it? Because when I tried to drop this database, I got this error
Mongo Server error (MongoCommandException): Command failed with error 8000 (AtlasError): 'user is not allowed to do action [dropDatabase] on [test.]' on server ac-bkmhuxm-shard-00-02.w2nutv2.mongodb.net:27017.
The full response is:
{
"ok" : 0.0,
"errmsg" : "user is not allowed to do action [dropDatabase] on [test.]",
"code" : 8000.0,
"codeName" : "AtlasError"
}
After changing the roles in Atlas, I can now delete the database. However it keeps appearing when I make a new connection to MongoDB. Why is that?
Database test is the default database when you don't define anything.
Databases local, admin and config are MongoDB system internal databases, you should not touch them unless advised by MongoDB support or special admin tasks.
See also 3 default database in MongoDB
So I was developing a project using mongo and I got an error after executing the code:
db.usercollection.insert({ "username" : "testuser1", "email" : "testuser1#testdomain.com" })
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: \"testuser1#testdomain.com\" } ], 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.
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();
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 !
I deploy a sharded cluster with the MongoDB version of 3.0.2.
I check the MongoDB 3.0 manual and find the command cleanupOrphaned.
http://docs.mongodb.org/manual/reference/command/cleanupOrphaned/#log-files
When I type this command from a mongos' admin database with the follow format:
db.runCommand({cleanupOrphaned:"mydb.mycol"})
it returns:
{ "ok" : 0, "errmsg" : "no such cmd: cleanupOrphaned", "code" : 59 }
Does anybody know why this happens???
Run cleanupOrphaned in the admin database directly on the mongod instance that is the primary replica set member of the shard. Do not run cleanupOrphaned on a mongos instance. It is given in the same link.
I'm trying to clone a remotely hosted collection to my local Mongo database. I tried opening up the mongo console in the local environment and issued:
db.runCommand({cloneCollection: "<dbname.colname>", from: "<remotehost:port>"})
It fails with
"errmsg" : "exception: nextSafe(): { $err: \"not authorized for query on <dbname>.system.namespaces\", code: 16550 }",
"code" : 13106,
How do I properly authorize with the remote server to clone the collection?
Unfortunately that's currently not possible. There is a Jira ticket open for this feature. As a workaround you could consider using mongodump --collection and mongorestore.
I installed mongohq:sandbox at Heroku. When I want to connect to mongo, it occurs an error:
mongo linus.mongohq.com:10123/app10575123 -u my_user -p pwd123
MongoDB shell version: 2.2.2
connecting to: linus.mongohq.com:10123/app10575123
> show dbs
Wed Jan 9 06:00:50 uncaught exception: listDatabases failed:{ "errmsg" : "need to login", "ok" : 0 }
Login and password are correct.
You are connected to the database, but for the shared database plans at MongoHQ (especially the sandbox ones), for security reasons, they do not include admin-level access to the Mongo instance ... only access to your actual database.
"show dbs" is an admin-level command and, in this case, would show other databases on that sandbox MongoDB process.
Instead, you will want to use commands like:
show collections
db.[collection_name].findOne()
db.stats()
db.[collection_name].stats()
db.[collection_name].ensureIndex({foo:1, bar:1}, {background:true})
... and so on.
I hope this helps!
You should be able to show collections, but show dbs requires admin privileges.