Abdul Moiz
Abdul Moiz

Reputation: 1327

MongoDB: Not authorized on database to execute command eval

This is the query i am running:

db.surveyquestion.copyTo('surveyquestionV2')

Error I am getting:

{
    "message" : "MongoError: not authorized on GenericSurveyTool to execute command { $eval: function (collName, newName) {\r" +
              "var from = db[collName];\r" +
              "..., args: [ 'surveyquestion', 'surveyquestionV2' ], $db: 'GenericSurveyTool' }",
    "stack" : "script:1:19",
    "code" : 13
}

My user in admin db that i am using to run this query:

query:  db.getUsers();


/* 2 */
{
    "_id" : "admin.moiz",
    "user" : "moiz",
    "db" : "admin",
    "roles" : [
        {
            "role" : "root",
            "db" : "admin"
        }
    ]
}

I have this user with the root role but still i am unable to copy collection. Please help!!

Upvotes: 1

Views: 6389

Answers (1)

Nicolas
Nicolas

Reputation: 457

To the people who has the same problem, the solution is in the documentation of db.eval() : just right here

If authorization is enabled, you must have access to all actions on all resources in order to run eval. Providing such access is not recommended, but if your organization requires a user to run eval, create a role that grants anyAction on anyResource. Do not assign this role to any other user.

Upvotes: 6

Related Questions