简体   繁体   English

Node.js Mongoose 是否允许您通过用户/密码连接到数据库?

[英]Does Node.js Mongoose allow you to connect to a database via a user/password?

How can I do that?我怎样才能做到这一点? Right now I can connect to the database, but it seems like only when no user is set...现在我可以连接到数据库,但似乎只有在没有设置用户的情况下......

http://mongoosejs.com/ http://mongoosejs.com/

It's version 1.0...but I can't find how to enter user/pass into the connection?它是 1.0 版...但我找不到如何输入用户/通过连接?

var db = mongoose.connect('mongodb://localhost/goaljuice');

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

http://www.tulek.org/2010/11/28/node-js-mongodb-mongoose/ http://www.tulek.org/2010/11/28/node-js-mongodb-mongoose/

http://www.mongodb.org/display/DOCS/Connections http://www.mongodb.org/display/DOCS/Connections

In mongodb, you have to assign collections to users before they can access them.在 mongodb 中,您必须先将 collections 分配给用户,然后才能访问它们。

db.addUser("theadmin", "anadminpassword")

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

HTH高温高压

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM