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.
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
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/
I would like to move the local implementations (mongoDB gridFS content repository) to cloud Heroku using mLAB. But I have a problem because some of the functionality of generating below error :
"errmsg" : "not authorized on admin to execute command {
listDatabases: 1.0 }", "code" : 13
Does anyone have an idea how to fix it?
Thanks for any help
I deployed my app using meteor deploy myapp.com, and directed my DNS to myapp.meteor.com.
The app is now available at myapp.com, and I have no problem running it. It's the correct version that was deployed to "myapp.com" and not the older "myapp.meteor.com" version.
But I cannot access mongodb for this deployed version.
When I run meteor mongo myapp.com, I get this at the terminal:
MongoDB shell version: 2.6.7
connecting to: sg-mother1-6242.servers.mongodirector.com:27017/myapp_com
2016-03-10T16:46:18.659-0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
I am also getting the same error when I run meteor mongo myapp.meteor.com:
MongoDB shell version: 2.6.7
connecting to: someserver.servers.mongodirector.com:27017/myapp_meteor_com
2016-03-10T16:45:54.367-0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
When I do meteor mongo --url myapp.com, I do get a URL back of the form:
mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
But I cannot connect to this URL using Robomongo. I get an error:
Cannot connect to MongoDB (<some-servername>.servers.mongodirector.com:27017),
error: Unable to connect to MongoDB
What am I doing wrong? How do I connect to the mongoDB for the app I deployed on my custom domain? Preferably using some GUI tool such as Robomongo?
What I understand, is that the local install of Meteor uses Mongodb 2.6 and newly deployed Meteor sites use Mongodb 3.0
When you call meteor mongo myapp.meteor.com you are using meteor's locally installed version of mongo (version 2.6) but you are trying to access the deployed mongodb (version 3.0). This results in the authentication error you are getting.
This link describes a workaround that worked for me. I had to tweak it a little, but this is what I did:
Install or update your local version of Mongo (not through Meteor).
Run the command meteor mongo --url myapp.meteor.com to get the MONGO_URL. As you already mentioned, you'll get something like
mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
Connect to the MONGO_URL using your updated non-meteor version of mongo by running
mongo mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
You should now be in the mongoshell, connected to your deployed mongodb. You should see something like this RS-mother1-0:PRIMARY> in your mongo shell. You still need to switch to your app's DB though. So call use myapp_com from the shell.
You should now be able to view collections and run mongo commands on your deployed meteor mongodb.
I'm not sure why you can't connect to Robomongo using the username and password meteor generates for you in the MONGO_URL. I suspect it's because it might expire. If you still want to connect using Robomongo, I'd recommend creating a user on the database now that you are logged in. And then later on, using that user to log into Robomongo.
Creating the user in the mongo shell:
db.createUser({ "user" : "my_user", "pwd": "my_password", "roles" : ["readWrite"]})
New MONGO_URL:
mongodb://my_user:my_password#<some-servername>.servers.mongodirector.com:27017/myapp_com
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.