Page History
...
Code Block |
---|
DROP INDEX myIndex ON NewItems |
CREATE USER
MongoDB 2.6+ CREATE USER user_name [GRANT role[, role, ...]] IDENTIFIED BY <password> [DESCRIPTION <string_value>]
This is equivalent to the createUser command (http://docs.mongodb.org/manual/reference/command/createUser/)
Info |
---|
In MongoDB 2.6 role can be user-defined roles. |
MongoDB 2.4 CREATE USER user_name GRANT role[, role, ...] IDENTIFIED BY <password>
role options are: READ, READWRITE, DBADMIN, USERADMIN, CLUSTERADMIN, READANYDATABASE, READWRITEANYDATABASE, USERADMINDATABASE, DBADMINANYDATABASE
Info |
---|
In MongoDB 2.4 multiple GRANT options can be specified as it supports role-based privileges. |
MongoDB 2.2 CREATE USER user_name GRANT [ READWRITE | READ ] IDENTIFIED BY <password>
Info |
---|
In MongoDB 2.2 only one GRANT option can be specified as it supports access-based privileges. |
CREATE USER generates a user for the MongoDB server.
Example
Code Block |
---|
CREATE USER jpizzle
GRANT READWRITE, USERADMIN IDENTIFIED BY '1337@55H@X0|2' |
ALTER USER
MongoDB 2.6+ ALTER USER <user_name> [IDENTIFIED BY <password>] [DESCRIPTION <string_value>]
ALTER USER updates a user profile for changing password and setting custom data in MongoDB Server
This is the equivalent of the updateUser command (http://docs.mongodb.org/manual/reference/command/updateUser/)
Example
Code Block |
---|
ALTER USER jpizzle IDENTIFIED BY '1337@55H@X0|2' |
DROP USER
DROP USER user_name
DROP USER removes a user for the MongoDB Server
Example
Code Block |
---|
DROP USER jpizzle |
GRANT ROLE TO USER
...
GRANT ROLE grants a role belonging to the current database or another database to a user. It grants one role at a time.
Example
Code Block |
---|
GRANT ROLE comrole DB mydatabase TO USER jpizzle |
REVOKE ROLE FROM USER
...
REVOKE ROLE revokes a role belonging to the current database or another database from a user. It revokes one role at a time.
Example
Code Block |
---|
REVOKE ROLE comrole DB mydatabase FROM USER jpizzle |
CREATE ROLE
MongoDB 2.6+ CREATE ROLE <new_role> PRIVILEGE [DB <db> COLLECTION <collection> | CLUSTER] ACTIONS <action> [, <action>, <action> ...]
...
CREATE ROLE creates a new role in the current database specifying the privilege or a role to inherit privileges.
<action> is a permitted action for the specified resource (http://docs.mongodb.org/manual/reference/privilege-actions/)
Example
Code Block |
---|
CREATE ROLE comrole PRIVILEGE DB mydatabase COLLECTION mycollection ACTIONS "find" |
Example
Code Block |
---|
CREATE ROLE all_baseball_role PRIVILEGE DB sports COLLECTION baseball ACTIONS "find", "insert", "remove", "update" |
DROP ROLE
MongoDB 2.6+ DROP ROLE role_name
DROP ROLE removes a role for the MongoDB Server
Example
Code Block |
---|
DROP ROLE comrole |
GRANT PRIVILEGE TO ROLE
...