[DOCS-6138] Comment on: "manual/reference/system-users-collection.txt" Created: 03/Sep/15  Updated: 03/Nov/17  Resolved: 06/Sep/15

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Roger Luo Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10

Location: http://docs.mongodb.org/manual/reference/system-users-collection/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
Referrer: http://docs.mongodb.org/manual/reference/built-in-roles/
Screen Resolution: 1366 x 768
repo: docs
source: reference/system-users-collection


Participants:
Days since reply: 8 years, 23 weeks, 3 days ago

 Description   

var MongoClient = require('mongodb').MongoClient;
MongoClient.connect(url, function(err, db) {
var adminDb = db.admin();
adminDb.addUser('admin', 'password', {
roles:[

{ role: 'userAdmin', db: 'admin' }

,

{ role: 'userAdminAnyDatabase', db: 'admin' }

,

{ role: "readWrite", db: "PMDB" }

]});
}
I can add the account successfully, but I cannot use the mongoose to connect the "PMDB" with admin account. I don't know why...

var connection = mongoose.connect('mongodb://admin:password@127.0.0.1:27017/PMDB');



 Comments   
Comment by Kay Kim (Inactive) [ 06/Sep/15 ]

Hi,
the user "admin" is defined in the admin database (i.e. the authenticationDatabase is admin database). And the user "admin" has roles in PMDB as well as admin, but the authenticationDatabase for this user is admin. So, once you authenticate the admin user against the admin database, you can switch database to PMDB and do read/write.

You might find StackOverflow a better forum for questions like these as DOCS tickets are mainly to report issues with the manual.

Regards,

Kay Kim

Generated at Thu Feb 08 07:51:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.