Authorization in mongodb

Read-only users only have read permissions. Thus, a user who has readonly true does not have the right to add new users or any write options.

I am creating a utility that manages data in MongoDB. When I log in as a read-only user, it should not allow me to add a new user. When I implement it, it does not actually add the user, but does not raise any exceptions.

Here are my commands for adding a read-only user

var credentials = new MongoCredentials(username, password,false);
var addUser = new MongoUser(credentials, readOnly);
var database = server.GetDatabase(databaseName);
database.AddUser(addUser);
+3
source share
1 answer

Did you start mongod with the --auth command line argument?

Do you safe=trueuse connections in your string?

, :

var adminCredentials = new MongoCredentials("adminuser", "adminpassword", true);
var userCredentials = new MongoCredentials("username", "password");
var user = new MongoUser(userCredentials, true);
var fooDatabase = server.GetDatabase("foo", adminCredentials);
fooDatabase.AddUser(user);

, : , .

+1

All Articles