Example
update: {
"$set": {
"title": "New Poem Title",
"lines.$[line0].key": ["i", "i", "t", "t", "s"],
"lines.$[line1].text": "Poopidy-scoop, scoop-dee-whoop"
},
"$push": {
"lines": {
"$each": [
{"order": 15, "text": "New line text", "key": ["i", "p"]}
]
}
"categories": {
"$each": ["exquisite", "dusty"]
}
},
}
arrayFilters: {
line0._id: ObjectId("as129qwOIN8D"),
line1._id: ObjectId("p10mfiWEROIM")
}
- Built-in solution to "array of objects" problem
- Logic already there, very little work to implement
- Looks (relatively) nice
- Bypasses Mongoengine, so... No validation!
- Lack of validation can introduce security risks (and make more difficult to debug)
- Updates are at the "database-level." This means we can't apply changes at the "application-level" (to create a temporary view of a document, for example.) In other words, all changes have to committed to DB.
update: {
"set__title": "New Poem Title",
"set__lines__0__text": "From whence we came we shall return"
"push__lines": {"order": 15, "text": "New line text", "key": ["i", "p"]}
"pull__categories": "dusty"
}
- Integrated with Mongoengine, so we have validation
- Logic already there, just have to plug into Mongoengine
- No solution to "array of objects" problem. (The only workaround splits the update operation into several separate operations, which is horrible for speed.)
- Once again, updates at "database-level." We cannot apply changes to actual Python objects.
- Doesn't map super cleanly to JS
- Map cleanly to Python objects, so we can apply changes at application-level.
- Provide solution to "array of objects" problem
- Map cleanly to JS, for convenient change tracking
- Validation
- JSON-Based