How to Access MongoDB
You can access MongoDB via the MongoDB Shell, or from within your programming environment using a MongoDB driver.
Once you have started a MongoDB instance (i.e. by using the
mongod command), you can now connect to that instance and start working with MongoDB.
You can use your computer's Terminal or Command Prompt to connect and run commands directly from the MongoDB Shell.
You can also connect to a running MongoDB instance via your programming environment by using a MongoDB driver.
MongoDB Shell (mongo)
Throughout this tutorial we'll use the MongoDB Shell (called mongo) to connect to our running MongoDB instance.
The MongoDB Shell is located in the same place as the other binaries. So to run it, open a new Terminal/Command Prompt window and enter
mongo (Linux/Mac) or
This assumes that the path has been added to your PATH. If it hasn't, you'll need to provide the full path.
Be sure to leave the mongod process open in its own Terminal/Command window. The above commands should be entered into a different Terminal/Command window to the one that the mongod process was started in.
Connect from your Programming Environment
You can also connect to MongoDB from within your programming environment.
The MongoDB website maintains a list of MongoDB drivers that can be used to connect to MongoDB.
This page includes drivers for the following languages:
- C++ (legacy)
Once you have connected to the mongod process, you can create a database.