connect()
説明
connect(url, user, password)
Creates a connection to a MongoDB instance and returns the reference to the database. However, in most cases, use the
Mongo()
object and itsgetDB()
method instead.Parameterタイプ説明url
string
Specifies the connection string. You can specify either:
<hostname>:<port>/<database>
<hostname>/<database>
<database>
user
string
Optional. Specifies an existing username with access privileges for this database. If
user
is specified, you must include thepassword
parameter as well.password
string
Optional unless the
user
parameter is specified. Specifies the password for theuser
.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
例
The following example instantiates a new connection to the MongoDB
instance running on the localhost interface and returns a reference
to myDatabase
:
db = connect("localhost:27017/myDatabase")
以下も参照してください。