CRUD Operations
Create Operations
Insert One Document
// Basic insert
db.users.insertOne({
name: "John Doe",
email: "john@example.com",
age: 30,
city: "New York"
})
// Insert with custom ObjectId
db.users.insertOne({
_id: ObjectId("507f1f77bcf86cd799439011"),
name: "Jane Doe",
email: "jane@example.com"
})
// Insert with timestamps
db.users.insertOne({
name: "Bob Smith",
email: "bob@example.com",
createdAt: new Date(),
updatedAt: new Date()
})
// Insert with nested objects
db.users.insertOne({
name: "Alice Johnson",
email: "alice@example.com",
profile: {
firstName: "Alice",
lastName: "Johnson",
bio: "Software Developer"
},
preferences: {
theme: "dark",
notifications: true
}
})Insert Multiple Documents
Insert with Upsert
Read Operations
Find All Documents
Find with Filters
Find with Projection
Find with Sorting
Find with Pagination
Find One Document
Count Documents
Update Operations
Update One Document
Update Multiple Documents
Update with Array Operators
Update with Field Operators
Replace Document
Delete Operations
Delete One Document
Delete Multiple Documents
Delete All Documents
Delete with Conditions
Bulk Operations
Bulk Write
Bulk Operations with Options
Last updated