Introduction to MongoDB Databases
In MongoDB, a database is a container for collections, and collections are containers for documents. Databases can be created and managed using the MongoDB shell. Let's walk through the process of creating your first MongoDB database.
Using the MongoDB Shell
We will use the MongoDB shell to create a database. Follow these steps:
- Open your command line terminal or PowerShell.
- Start the MongoDB server if it's not already running (you can follow the steps from the previous guide).
- Open the MongoDB shell by typing the following command:
mongo
use myFirstDB
db.myCollection.insertOne({ name: "John", age: 30 })
Now, the "myFirstDB" database is created, and it contains the "myCollection" collection with one document.
Viewing Your New Database
You can list all the databases in your MongoDB server by running the following command in the MongoDB shell:
show dbs
Your "myFirstDB" should appear in the list of databases.
Conclusion
Congratulations! You've created your first MongoDB database. MongoDB is a versatile database system that can store and manage your data efficiently. You can continue to work with your database, insert more data, and explore the many features MongoDB has to offer.