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"

1
  • are any of those answers acceptable? Jan 12, 2017 at 6:24

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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