Collection.multiUpdateObject(dbApiKey, collectionName, queryString, updateJSON, operationsJSON[, token])
Updates multiple objects selected by a query with new values. The function returns a 200 code with empty response body.
#Parameters The method has the following parameters:
Argument | Description | Required |
---|---|---|
dbApiKey |
Database API key. |
Yes. |
token |
String with user token or database Master key. |
No. |
collectionName |
String with database collection name. |
Yes. |
queryString |
Query to select which objects will be updated. The JSON query object that was built in accordance with the documentation of MongoDB query. |
Yes. |
updateJSON |
JSON object with fields of object that should be updated. |
No. |
operationsJSON |
JSON update object with native MongoDB operations and fields of object that should be updated. The object was built in accordance with the documentation of MongoDB set operations. If
Native operations works on the following data types: number, string, boolean, date. |
No. |
Examples
The following examples finds all students who are transfer students and then updates their major to undecided. This example uses the updateJSON parameter.
var dbApiKey = "57928860e4b00ef864f3dc24";
var result = Collection.multiUpdateObject(
dbApiKey,
"Student",
'{isTransferStudent: true}',
{"major": {'name':'undecided'}}
);
This example performs an update using the native MongoDB operations (with operationsJSON parameter). This code will change any students who are transfer students to non-transfer students.
var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', null, {
"$set": {"isTransferStudent": false}
});
Note that native operations work on the following data types: number, string, boolean, date.