MongoDB Assignment- 1
Basic Questions
- Run a MongoDB command that prints “Connected to a NoSQL Database” when you connect in the shell.
- Create three collections (keyvalueDB, documentDB, graphDB) in one MongoDB database to represent different NoSQL types.
- Insert two documents into a collection showing schema flexibility (MongoDB) vs fixed table in SQL.
- Run db.runCommand({ buildInfo: 1 }) and log database type to confirm MongoDB is document‑oriented.
- Insert a demo document with large array + nested object to showcase MongoDB’s flexibility/advantage.
- Connect to MongoDB shell and run db.serverCmdLineOpts() to see the default port.
- Create a document {company: “MongoDB Inc.”} in a collection about and query it back.
- Open mongosh in terminal to prove shell access.
- Create a collection students and describe it as “Like a SQL table”.
- Insert one document {name: “Alice”, age: 22} and explain it as MongoDB’s atomic unit.
- Run use library to define a new database.
- Insert and then display BSON representation of a document to demonstrate storage format.
- Write a simple JSON-like MongoDB document for a student with name and age.
- Show BSON by inserting binary data, explaining “BSON” stands for binary JSON.
- Insert a document using ObjectId + Date to demo BSON datatypes beyond JSON
- Launch MongoDB Compass and connect to your local DB.
- Signup to MongoDB Atlas and create a free cluster.
- In mongosh, run show dbs to display all databases.
- Run use school to create new DB.
- Run show collections in the shell.
Intermediate Questions
- Create one table in SQL and one MongoDB collection with same data, compare them side by side.
- Insert a document into collection to demonstrate document‑oriented storage.
- Write MongoDB shell commands to create a collection named employees.
- Insert a document into employees with fields: name, position, and salary.
- Show the command to display all documents from the employees collection.
- Insert without _id and check auto‑generated _id field.
- Show how to insert multiple documents at once into a collection.
- Write MongoDB shell command to switch to the ecommerce database.
- Insert same dataset in SQL table and MongoDB collection, compare structure.
- Display any inserted MongoDB document as key‑value structure.
- Insert and inspect BSON Date to show why BSON > JSON.
- Give an example of a nested document in MongoDB.
- Insert three BSON datatypes (NumberInt, Date, ObjectId) and query them.
- Write a MongoDB query to find all students with age greater than 18.
- Insert one doc with insertOne and multiple docs with insertMany.
- Connect DB with Compass and shell, compare the views.
- Show how to connect to a MongoDB Atlas cluster from CLI.
- Connect Atlas cluster remotely and local MongoDB, compare performance on inserts.
- Write a query to delete a document where name = “John”.
- Write a query to update the salary of an employee named “Alice” to 60,000.
Advanced Questions
- Create two collections flexibleUsers (MongoDB) and strictUsers (simulate table rules) showing schema flexibility.
- Design a MongoDB database for a library system with collections for books, authors, and members.
- Show a BSON example that contains string, number, boolean, date, array, and nested object.
- Write a MongoDB command to insert a user document with nested address and array of phone numbers.
- Create a document representing an order with fields: orderId, customer, items (array of objects), totalPrice.
- Setup MongoDB Atlas cluster, replicate nodes, and demonstrate failover support.
- Design a MongoDB document for a social media post with user, content, likes, and an array of comments.
- Insert 100,000 documents and check size in BSON vs exported JSON.
- Create a MongoDB command that inserts a document with a BSON Date type and retrieve only the year.
- Insert documents and try querying by _id to demonstrate why _id ensures uniqueness.
