This project demonstrates my understanding of MongoDB fundamentals, including database setup, CRUD operations, advanced queries, aggregation pipelines, and indexing.
- Ensure MongoDB is installed locally OR you have a MongoDB Atlas cluster.
- If using local MongoDB, make sure the service is running:
mongod
2️⃣ Run the Data Insertion Script
The script insert_books.js connects to MongoDB and inserts 12 sample books into the plp_bookstore database.
Run it using Node.js:
node insert_books.js
You should see a message confirming that 12 books were inserted.
3️⃣ Verify the Data
Open Mongo Shell (mongosh):
mongosh use plp_bookstore show collections db.books.find().pretty()
You should see all the inserted books displayed.
🧪 CRUD & Advanced Queries
All queries are stored in the queries.js file for reference. You can open mongosh and run each command manually.
Example Commands: // Find all Fiction books db.books.find({ genre: "Fiction" }).pretty();
// Update price of "The Great Gatsby" db.books.updateOne({ title: "The Great Gatsby" }, { $set: { price: 11.99 } });
// Delete "Moby Dick" db.books.deleteOne({ title: "Moby Dick" });
The file also contains:
Queries for projection, sorting, and pagination
Aggregation pipelines (average price by genre, author with most books, decade grouping)
Index creation and performance testing with explain()
📂 Project Files File Description insert_books.js Script that connects to MongoDB and populates the database with book data queries.js Contains all required CRUD, advanced, and aggregation queries README.md Instructions for setup and running the project screenshot.png Screenshot of MongoDB Compass or mongosh showing the collection and data