Reputation: 21955
My databases have their own users set, and now I want to eval certain functions, like:
function() {
db.mydatabase.ensureIndex(<fields>, <options>);
}
But that never works, I get an unauthorized error.
But the user IS authorized and authenticated. If now, I wouldn't be able to connect. The user also has the dbAdmin role set, which I thought was needed for version 2.4 and up.
I tried to login using an admin user, but that doesn't work unless you log into the admin database itself.
This is the user of 'mydatabase':
{ "_id" : ObjectId("534290d2bfeb13f0b91d52d3"), "user" : "myuser", "pwd" : "blabla", "roles" : [ "read", "readWrite", "dbAdmin", "userAdmin", "clusterAdmin", "readAnyDatabase", "readWriteAnyDatabase", "userAdminAnyDatabase", "dbAdminAnyDatabase" ] }
Upvotes: 0
Views: 277
Reputation: 151122
The concept of where you can use eval
in your programming is very much covered both here and importantly here.
The short points are:
You need special permissions in order to be able to use the command, as well as take into consideration that you cannot do this on sharded clusters.
From the second link this can be explicitly disabled on the instance startup. So it is probably good practice of hosting providers to do this by default in their setup.
While eval
does have some valid usages in a "get out of jail" sense to solve specific "one-off" problems when altering collection formats, the general usage in production environments should be discouraged.
As the second link suggests, search for other alternatives to using the eval form when running in production environments. There are serious problems around the corner if you persist in actually doing this.
Upvotes: 1