2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to put username & password in MongoDB?

I want to set up the user name & password for my mongoDB. so that any remote access will ask for the user name & password. Is there a way to do it? I tried the tutorial from the mongodb site and did following:


use admin

db.addUser("theadmin", "12345");

db.auth("theadmin","12345");


After that, I exit and run mongo again. And I don"t need password to access it. Even I connect to the mongodb remotely, I am not prompted for user name & password.

userimage

You need to start mongod with the --auth option after setting up the user.

From the MongoDB Site: Run the database (mongod process) with the --auth option to enable security. You must either have added a user to the admin db before starting the server with --auth, or add the first user from the localhost interface.

http://www.mongodb.org/display/DOCS/Security+and+Authentication

Answer is