문제

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" } });
도움이 되었습니까?

해결책

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')

다른 팁

Best way to do it is -

'mongodb://' + mongo_username + ':' + encodeURIComponent(mongo_password) + '@' 
+ ip + ':27017/' + dbName+ '?authSource=admin'

encodeURIComponent() is used for, if password contains special chars

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top