multiUpdateObject

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:

ArgumentDescriptionRequired
dbApiKeyDatabase API key.Yes.
tokenString with user token or database Master key.No.
collectionNameString with database collection name.Yes.
queryStringQuery to select which objects will be updated. The JSON query object that was built in accordance with the documentation of MongoDB query.Yes.
updateJSONJSON object with fields of object that should be updated.No.
operationsJSONJSON 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 object specified than update param fully ignored. Their functionality cannot be used simultaneously. The following operations are supported:
$set
$unset
$inc (Number type only)
$mul (Number type only)
$min (Number and Date type only)
$max (Number and Date type only).

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 the update sets their major to undecided. This examples uses updateJSON parameter.

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', {"major": {'name':'undecided'}
});
This example performs an update suing the native MongoDB operaitons (with operationsJSON parameter). This code will change any students who are transfer student to non-transfer students.

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', null, {
  "$set": {"isTransferStudent":false}
});
Not that native operations works on the following data types: number, string, boolean, date.