On this page本页内容
connect(url, user, password)
Creates a connection to a MongoDB instance and returns the reference to the database. 创建到MongoDB实例的连接,并返回对数据库的引用。However, in most cases, use the 但是,在大多数情况下,使用Mongo()
object and its getDB()
method instead.Mongo()
对象及其getDB()
方法。
url | string |
|
user | string | user is specified, you must include the password parameter as well.user ,则还必须包括密码参数。
|
password | string | user parameter is specified. user 参数。user . |
The following example instantiates a new connection to the MongoDB instance running on the localhost interface and returns a reference to 以下示例实例化了一个到本地主机接口上运行的MongoDB实例的新连接,并返回对myDatabase
:myDatabase
的引用:
db = connect("localhost:27017/myDatabase")