0
0
MongoDBquery~10 mins

Schema versioning strategies in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a version field to a MongoDB document.

MongoDB
db.collection.insertOne({ name: "Alice", age: 30, version: [1] })
Drag options to blanks, or click blank then click option'
A1
B"v1"
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for version.
Omitting the version field entirely.
2fill in blank
medium

Complete the code to update the schema version of all documents to 2.

MongoDB
db.collection.updateMany({}, { $set: { version: [1] } })
Drag options to blanks, or click blank then click option'
A2
B"2"
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "2" instead of number 2.
Using null or true instead of a version number.
3fill in blank
hard

Fix the error in the query to find documents with version 1.

MongoDB
db.collection.find({ version: [1] })
Drag options to blanks, or click blank then click option'
A"1"
B1
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "1" which does not match the numeric field.
Using true or null which are incorrect types.
4fill in blank
hard

Fill both blanks to add a new field only to documents with version less than 2.

MongoDB
db.collection.updateMany({ version: { [1]: 2 } }, { $set: { [2]: "legacy" } })
Drag options to blanks, or click blank then click option'
A$lt
B$gt
Cstatus
Dversion
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt for filtering.
Setting the field name as 'version' which overwrites existing data.
5fill in blank
hard

Fill all three blanks to rename the field 'oldField' to 'newField' in documents with version 1.

MongoDB
db.collection.updateMany({ version: [1] }, { $rename: { [2]: [3] } })
Drag options to blanks, or click blank then click option'
A1
B"oldField"
C"newField"
D"version"
Attempts:
3 left
💡 Hint
Common Mistakes
Using version as a string instead of number.
Not quoting field names in $rename operator.