0
0
MongoDBquery~30 mins

MongoDB installation and setup - Mini Project: Build & Apply

Choose your learning style9 modes available
MongoDB Installation and Setup
📖 Scenario: You have MongoDB installed and need to verify it's working by connecting, creating a database, inserting a document, and querying it back. This confirms your installation is properly configured.
🎯 Goal: Connect to MongoDB, create a database and collection, insert a document, and query it to verify the setup is working end to end.
📋 What You'll Learn
Connect to MongoDB and switch to a new database
Create a collection by inserting a document
Query the document back to verify it was saved
Check database and collection statistics
💡 Why This Matters
🌍 Real World
Verifying a MongoDB installation with basic CRUD operations is the first step before building any application on top of MongoDB.
💼 Career
Every MongoDB developer needs to know how to create databases, insert documents, and query data using the shell — it's the foundation for all MongoDB work.
Progress0 / 4 steps
1
Switch to a new database
Use the use command to switch to a database called myapp. MongoDB creates the database automatically when you first store data in it.
MongoDB
Need a hint?

Type use myapp in the MongoDB shell to switch to or create the database.

2
Insert a document into a collection
Use db.users.insertOne() to insert a document with fields name set to "Alice", email set to "alice@example.com", and age set to 30.
MongoDB
Need a hint?

Use db.users.insertOne({ key: value }) to insert a single document into the users collection.

3
Query the document back
Use db.users.find() with a filter of { name: "Alice" } to retrieve the document you just inserted.
MongoDB
Need a hint?

Use db.users.find({ name: "Alice" }) to search for documents matching the filter.

4
Check database statistics
Run db.stats() to check the current database statistics, confirming data was stored successfully. Then run show collections to list all collections in the database.
MongoDB
Need a hint?

Use db.stats() for database statistics and show collections to see all collections.