Reputation: 616
I have created application using mongodb+nodejs
I have added new user with following roles in mongodb
{
"_id" : "testdb.testdbuser",
"user" : "testdbuser",
"db" : "testdb",
"roles" : [
{
"role" : "read",
"db" : "testdb"
},
{
"role" : "readWrite",
"db" : "testdb"
}
]
}
Started server using --auth
option.
And also started node application using mongodb user credentials.
But, I am not able to read data from user
collection in testdb
database.
Getting this error :
MongoError: not authorized for query on testdb.user
Please any suggestion? Anything I am missing?
Upvotes: 0
Views: 658
Reputation: 4263
You need to assign the read role to the user testdbuser.
testsdbuser role does not include read access on non-system collections. You can give it like this, it seems,
db.grantRolesToUser(
"testdbuser",
[
{ role: "read", db: "testdb" }
]
)
Upvotes: 1