How do I add a user that has read access to only ONE database? 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"
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.