1

I'm using mongodb with Node.js and I make my connection as follows:

var mongoClient = new MongoClient(new Server("localhost", 27017,
{ native_parser: true }
));
mongoClient.open(function (err, mongoclient) {
    db = mongoclient.db('mydb');
});

As it is clear It requires no password, My concern is that how to set up password with mongodb and when I try to make connection then It should require password. How to do it?

M Omayr
  • 1,351
  • 1
  • 9
  • 19

2 Answers2

1

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

Dileephell
  • 620
  • 2
  • 7
  • 18
1

Here is the resource
http://www.hacksparrow.com/mongodb-add-users-and-authenticate.html
mongod --auth --setParameter enableLocalhostAuthBypass=0 the last option is to disable localhost bypass..

Dex
  • 333
  • 1
  • 3
  • 8