Complete the code to add a version field to a MongoDB document.
db.collection.insertOne({ name: "Alice", age: 30, version: [1] })The version field is typically a number to track schema versions. Here, 1 is used.
Complete the code to update the schema version of all documents to 2.
db.collection.updateMany({}, { $set: { version: [1] } })Schema versions are numeric. Here, we set version to 2 as a number.
Fix the error in the query to find documents with version 1.
db.collection.find({ version: [1] })The version field is stored as a number, so the query must use number 1, not string "1".
Fill both blanks to add a new field only to documents with version less than 2.
db.collection.updateMany({ version: { [1]: 2 } }, { $set: { [2]: "legacy" } })Use $lt to find documents with version less than 2, and add a new field 'status' with value 'legacy'.
Fill all three blanks to rename the field 'oldField' to 'newField' in documents with version 1.
db.collection.updateMany({ version: [1] }, { $rename: { [2]: [3] } })We filter documents with version 1, then rename 'oldField' to 'newField' using $rename operator.