- Reference >
- JavaScript Methods >
- connect()
connect()¶
-
connect
(<hostname><:port>/<database>)¶ The
connect()
method creates a connection to a MongoDB instance. However, use theMongo()
object and itsgetDB()
method in most cases.connect()
accepts a string<hostname><:port>/<database>
parameter to connect to the MongoDB instance on the<hostname><:port>
and return the reference to the database<database>
.The following example instantiates a new connection to the MongoDB instance running on the localhost interface and returns a reference to
myDatabase
:See also