Complete the code to insert a new document into the collection.
db.collection.[1]({ name: "Alice", age: 30 })
The insertOne method adds a new document to the collection, which is essential for write-heavy workloads.
Complete the code to create an index that improves write performance by avoiding duplicates.
db.collection.createIndex({ email: 1 }, { [1]: true })The unique option ensures no duplicate emails, which helps maintain data integrity in write-heavy workloads.
Fix the error in the update operation to increment the 'count' field by 1.
db.collection.updateOne({ _id: 1 }, { [1]: { count: 1 } })The $inc operator increments a numeric field by the specified value, perfect for counters in write-heavy workloads.
Fill both blanks to create a schema design that embeds comments inside posts for faster writes.
const commentSchema = new Schema({ text: String, date: [2] }); const postSchema = new Schema({ title: String, comments: [[1]] });Embedding commentSchema inside posts allows fast writes by storing related data together. The Date type is used for the comment date.
Fill all three blanks to write a bulk insert operation for multiple user documents.
db.users.[1]([{ name: "John" }, { name: "Jane" }], { [2]: true, [3]: 1000 })
insertMany inserts multiple documents at once. The ordered option controls if operations stop on error. w sets acknowledgment level for writes, important in write-heavy workloads.