Creating & Finding Documents

🍁 MongoDBLesson 4Beginner

Basic write operations in MongoDB are performed using insertOne and insertMany. Querying documents is done using the find command.

1 CRUD Syntax
JavaScript — Database Queries
# 1. Insert one document
db.users.insertOne({ name: "Balaji", age: 25 });

# 2. Insert multiple documents
db.users.insertMany([
  { name: "Priya", age: 22 },
  { name: "Vikram", age: 30 }
]);

# 3. Query all documents
db.users.find();

# 4. Filter queries with projection (selecting specific fields)
db.users.find({ age: 25 }, { name: 1, _id: 0 });
2 Code Challenge
Challenge: Write query commands inserting three product documents, and write a find query selecting only products that match a specific category name.