Complete the code to perform an upsert operation in MongoDB.
db.collection.updateOne({ _id: 1 }, { $set: { name: 'Alice' } }, { [1]: true })The upsert option tells MongoDB to insert a new document if no matching document is found during the update.
Complete the code to update a document or insert it if it does not exist.
db.users.updateOne({ username: 'bob' }, { $set: { age: 30 } }, { [1]: true })The upsert option ensures the document is inserted if it does not exist.
Fix the error in the upsert operation code.
db.products.updateOne({ sku: '123' }, { $set: { price: 20 } }, { [1]: true })The upsert option must be a boolean true, not a string like 'yes'.
Fill both blanks to create an upsert that sets the field and returns the updated document.
db.inventory.updateOne({ item: 'pencil' }, { [1]: { qty: 50 } }, { [2]: true, returnDocument: 'after' })Use $set to update the field and upsert: true to insert if missing.
Fill all three blanks to perform an upsert that increments a count, sets a status, and enables upsert.
db.stats.updateOne({ user: 'john' }, { [1]: { count: 1 }, [2]: { status: 'active' } }, { [3]: true })Use $inc to increase count, $set to update status, and upsert: true to insert if missing.