2

I have two databases admin and testdb ; Added a user Alice in the test database

db.addUser( { user: "Alice",pwd: "Moon1234",roles: [ "readWrite" ] } );

But when I login using the user Alice, I can run "use admin" and run all read queries on that database.

Then I tried doing this:

db.addUser( { user: "Alice",userSource: "testdb",roles: [ "readWrite" ] } )

I get this error:

uncaught exception: couldn't add user: 'testdb' is not a valid value for the userSource field in testdb.system.users entries

Mongodb documentation is not very clear about it.

Basically my use case is that Alice should be able to read write ONLY in the "testdb"

  • are any of those answers acceptable? – Evan Carroll Jan 12 '17 at 6:24
2

I don't know MongoDB too well and I assume you have you seen the information set out on the MongoDB System Users page as there would seem to be one or two differences across different DB mangement procedures.

As a suggestion have you set the database you wish to work on/from by adding the 'use ....' before the command. It would seem that you might try:-

use admin
db.addUser( { user: "Alice",userSource: "testdb",roles: [ "readWrite" ] } )

and see if that makes a difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.