const collectionName = 'Students';
const url = `/domo/datastores/v2/collections/${collectionName}/documents/update`;
// $set — appoint Hermione and Ron as prefects
domo.put(url, {
query: { 'content.name': { $in: ['Hermione Granger', 'Ron Weasley'] } },
operation: { $set: { 'content.prefect': true } }
}).then(count => console.log(count + ' document(s) updated'));
// $addToSet — add a course only if Harry isn't already enrolled
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $addToSet: { 'content.courses': 'Remedial Potions' } }
}).then(count => console.log(count + ' document(s) updated'));
// $push + $each + $sort — enroll Harry in two electives and keep the list alphabetical
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $push: { 'content.courses': { $each: ['Divination', 'Astronomy'], $sort: 1 } } }
}).then(count => console.log(count + ' document(s) updated'));
// $currentDate — stamp the moment Harry was caught out after curfew.
// Note: $currentDate stores a BSON Date, not a string. Query it with
// {"content.caughtAfterCurfewAt": {"$lt": {"$date": "..."}}} not plain string comparison.
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $currentDate: { 'content.caughtAfterCurfewAt': true } }
}).then(count => console.log(count + ' document(s) updated'));
// $pull — Draco drops Defense Against the Dark Arts
domo.put(url, {
query: { 'content.name': 'Draco Malfoy' },
operation: { $pull: { 'content.courses': 'Defense Against the Dark Arts' } }
}).then(count => console.log(count + ' document(s) updated'));
// $unset — clear detention records for all Gryffindors at year end
domo.put(url, {
query: { 'content.house': 'Gryffindor' },
operation: { $unset: { 'content.lastDetention': '' } }
}).then(count => console.log(count + ' document(s) updated'));2{
"message": "JSON parse error: Instantiation of [simple type, class com.domo.magnum.model.documents.DocumentUpdate] value failed for JSON property query due to missing (therefore NULL) value for creator parameter query which is a non-nullable type",
"status": 400,
"statusReason": "Bad Request",
"toe": "APS9BQQ3SQ-HJJ5D-9MRP6"
}{
"status": 403,
"statusReason": "status 403 reading DocumentsResourceClient#updateDocument(UUID,UUID,DocumentDefinition)",
"toe": "BU22GXWMDI-ILY50-5YX28"
}{
"status": 404,
"statusReason": "DA0088: Invalid collection name: students",
"toe": "C7Z7W7ILTW-D2P1Y-9QKHK"
}Partially Update Documents
Partially updates documents matching a query using MongoDB update operators.
Supported operators
$currentDate · $inc · $min · $max · $mul · $rename · $set · $unset · $addToSet · $pop · $pull · $pullAll · $push
Supported modifiers
$each · $position · $slice · $sort
$setOnInsert has no effect — partial updates do not perform upserts.
See the MongoDB update operator documentation for full semantics.
PUT
/
domo
/
datastores
/
v2
/
collections
/
{collectionName}
/
documents
/
update
const collectionName = 'Students';
const url = `/domo/datastores/v2/collections/${collectionName}/documents/update`;
// $set — appoint Hermione and Ron as prefects
domo.put(url, {
query: { 'content.name': { $in: ['Hermione Granger', 'Ron Weasley'] } },
operation: { $set: { 'content.prefect': true } }
}).then(count => console.log(count + ' document(s) updated'));
// $addToSet — add a course only if Harry isn't already enrolled
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $addToSet: { 'content.courses': 'Remedial Potions' } }
}).then(count => console.log(count + ' document(s) updated'));
// $push + $each + $sort — enroll Harry in two electives and keep the list alphabetical
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $push: { 'content.courses': { $each: ['Divination', 'Astronomy'], $sort: 1 } } }
}).then(count => console.log(count + ' document(s) updated'));
// $currentDate — stamp the moment Harry was caught out after curfew.
// Note: $currentDate stores a BSON Date, not a string. Query it with
// {"content.caughtAfterCurfewAt": {"$lt": {"$date": "..."}}} not plain string comparison.
domo.put(url, {
query: { 'content.name': 'Harry Potter' },
operation: { $currentDate: { 'content.caughtAfterCurfewAt': true } }
}).then(count => console.log(count + ' document(s) updated'));
// $pull — Draco drops Defense Against the Dark Arts
domo.put(url, {
query: { 'content.name': 'Draco Malfoy' },
operation: { $pull: { 'content.courses': 'Defense Against the Dark Arts' } }
}).then(count => console.log(count + ' document(s) updated'));
// $unset — clear detention records for all Gryffindors at year end
domo.put(url, {
query: { 'content.house': 'Gryffindor' },
operation: { $unset: { 'content.lastDetention': '' } }
}).then(count => console.log(count + ' document(s) updated'));2{
"message": "JSON parse error: Instantiation of [simple type, class com.domo.magnum.model.documents.DocumentUpdate] value failed for JSON property query due to missing (therefore NULL) value for creator parameter query which is a non-nullable type",
"status": 400,
"statusReason": "Bad Request",
"toe": "APS9BQQ3SQ-HJJ5D-9MRP6"
}{
"status": 403,
"statusReason": "status 403 reading DocumentsResourceClient#updateDocument(UUID,UUID,DocumentDefinition)",
"toe": "BU22GXWMDI-ILY50-5YX28"
}{
"status": 404,
"statusReason": "DA0088: Invalid collection name: students",
"toe": "C7Z7W7ILTW-D2P1Y-9QKHK"
}