When adding a user to multiple databases, use unique username-and-password combinations for each database
While this sentence is true for itself, it may lead to the conclusion that a user who needs to access different databases has to be added to each database individually.
However, it's recommended to add such an user only once by giving him/her multiple roles for all the databases he/she needs to access.
For example:
{
|
_id: "home.Kari",
|
user: "Kari",
|
db: "home",
|
credentials: { "MONGODB-CR" :"<hashed password>" },
|
roles : [
|
{ role: "read", db: "home" },
|
{ role: "readWrite", db: "test" },
|
{ role: "appUser", db: "myApp" }
|
],
|
customData: { zipCode: "64157" }
|
}
|
This user has been added only once to the home database having access to the three databases home, test and myApp.
See: http://docs.mongodb.org/manual/reference/system-users-collection/
|