Monthly Archives: July 2014

MongoDB – adding a read/write user to a database

The commands are different in different versions of MongoDB for authenticating a user against a database.

Let us say we have to authenticate user joe with password secret as a read/write user for database mydb.

Mongo 2.2:

Mongo 2.4:

Mongo 2.6:

dbAdmin: If you also want to make the readWrite user as an admin for the database, in Mongo 2.4 and 2.6, you should add dbAdmin to roles. (I don’t know if an “admin user” is applicable for Mongo 2.2, and if yes, what the command is.)