mongodbexpressmongoosesession-store

To connect MongoStore to a db and auth with the admin one


Is there a way to instanciate a MongoStore to a db and auth with the "admin" one ?

Like this with mongoose:

var db = mongoose.createConnection('mongodb://myname:mypwd@localhost:27017/mydb', { auth: { authdb:"admin" } });

Solution

  • When you talk about MongoStore do you mean this project - https://github.com/diversario/connect-mongostore ?

    If you do then the answer is yes, it uses the same syntax as URI part of mydb example. You just need to change the values in the user and password fields to the appropriate for your database. In the snippet below, it is connecting to the mongod instance running on port 27101 with a username of 'user' and a password of 'password' to the 'admin' database.

    new MongoStore('mongodb://user:password@127.0.0.1:27017/admin')