I’m trying to use command copydb in mongodb.
When I do so I get the following exception:
Command 'copydb' failed: access denied; use admin db (response: { "errmsg" : "access denied; use
admin db", "ok" : 0.0 })
I have tried to log in as admin but failed because I’m not using username & password.
How do I log in as admin without username & password?
Why do I need to log in as admin if I already have privileges to do drop?
Thanks in advance
m_mongoDatabase.RunCommand(new CommandDocument(new BsonElement("copydb", (BsonValue) 1),
new BsonElement("fromdb", (BsonValue) from),
new BsonElement("fromhost", (BsonValue) fromHost),
new BsonElement("todb", (BsonValue) to)));
I think the problem is that you are not connecting to the “admin” database on the target instance first.
I can perform the operation you require using the following code:
Notice that I acquire a ref to the admin database first. When I didn’t do that and used another regular database I got the same error as you.
So to recap, use the admin database for the value of “m_mongoDatabase”
Hope this helps
Edit:This is the same behaviour when using the mongodb shell, so it doesn’t appear to be an issue with the csharpdriver