I'm new for mongodb.
i'm trying to understand how user privileges work on mongodb i have a mongodb data base ( from mongoHQ sandbox 512 Mb free ).
and also i create a database and it contains some collections here how it looks like
here is my database events and its collections (messages,*provider*)
events
- messages
- provider
what i want is : i have 3 users with 3 different privileges on events database's different collections
here are 3 users with their privileges
providerUser : readonly access on provider collection and don't have access events database's other collections (and have no access on other data bases also )
eventreadUser : readonly access on message collection on events data base and don't have access to other collections on events database (and have no access on other data bases also )
eventreadWriteUser :only have read,write access on message collection on events data base and don't have access to other collections on events database (and have no access on other data bases also )
so i created a javascript that add these users to events database
addUsers.js
var conn = new Mongo('hostname:port');
var db = conn.getDB("events");
// For authentification on DB
db.auth('username', 'password');
function addCurlUserAndroidUser() {
var providerUser = {
user: 'providerUser',
pwd: 'providerUserPassword',
privileges: [{
resource: {collection: "provider" },
actions: [ "find"]
}],
roles: [ "read"]
};
var eventreadUser = {
user: 'eventreadUser',
pwd: 'eventreadUserPassword',
privileges: [{
resource: { collection: "messages" },
actions: [ "find"]
}],
roles: [ "read"]
};
var eventreadWriteUser = {
user: 'eventreadWriteUser',
pwd: 'eventreadWriteUserPassword',
privileges: [{
resource: { collection: "messages" },
actions: [ "find", "insert","remove","update"]
}],
roles: [ "readWrite"]
};
db.addUser(eventreadUser);
db.addUser(providerUser);
db.addUser(eventreadWriteUser);
}
after i execute this javascript by following command line :
mongo hostname:port/events addUsers.js
the problem is providerUser have access to read messages collection and eventreadUser , eventreadWriteUser can also have access to read provider collection
please ask more information if needed or if there something not clearly explained it will be very useful if i get some useful responses very quickly
Thank you
Dinesh