The following page provides various examples for querying in the MongoDB shell. For examples using MongoDB drivers, refer to the links in the Additional Examples section.
Click inside the shell to connect. Once connected, you can run the examples in the shell above.
Within the shell,
db refers to
your current database. Type
db to display the current
The operation should return
test, which is the default
To switch databases, type
use <db>. For example, to switch
You do not need to create the database before you switch. MongoDB creates the database when you first store data in that database (such as create the first collection in the database).
To verify that your database is now
the shell above.
To create a collection in the database, see the next tab.
Set up Your Own Deployment¶
To set up your own deployment:
For additional examples, including MongoDB driver specific examples (Python, Java, Node.js, etc.), see: