I have databases A, B, C, in addition to system's admin
I want to add a user that has readWrite access to A, B, C.
// attempt 1
use admin
db.createUser({ user: "Bob", pwd: "1234", roles: [
{ role: "readWriteAnyDatabase", db: "admin" }
] })
.
// attempt 2
use admin
db.createUser({ user: "Bob", pwd: "1234", roles: [
{ role: "readWrite", db: "A" },
{ role: "readWrite", db: "B" },
{ role: "readWrite", db: "C" }
] })
For these attempts, the user is stored in db admin. So how can I authenticate using admin but perform actions in one of A, B, C?
var uri = 'mongodb://localhost/A';
var opts = {
user: 'Bob',
pass: '1234',
auth: { authDb: 'admin' }
};
mongoose.connect(uri, opts); // auth fails
Is my only solution to separately add a user on each of A, B, C ? Ex.
use A
db.createUser({...})
use B
db.createUser({...})
use C
db.createUser({...})
Seems foolish.