- Reference >
- mongo Shell Methods >
- Connection Methods >
- connect()
connect()¶
- connect(<hostname><:port>/<database>)¶
The connect() method creates a connection to a MongoDB instance. However, use the Mongo() object and its getDB() 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:
db = connect("localhost:27017/myDatabase")
See also
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.