Collection.updateObject(dbApiKey, collectionName, objectId, objectJSON[, token])
Updates an object with new values.
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 name of collection. | Yes. |
objectID | Unique identifier of object that should be updated. | Yes. |
objectJSON | JSON object which holds columns and new data. Only field which are sent in this object will be updated. Columns not present will not be updated. | Yes. |
Response
The function returns the time stamp when the object was modified:
Argument | Description |
---|---|
_updatedAt | Time stamp when the object was modified. |
{
"_updatedAt":{"$date":<update>}
}
Examples
This example shows how to update three columns in the Student collection. Columns for which data is not sent are not updated (values are unchanged).
var dbApiKey = "c33010af-f263-4443-9897-c2ffaf522956";
var result = Collection.updateObject(dbApiKey, "Student", "57a52796e4b03647ddae32a5", {
"isTransferStudent": true,
"major": {"name":"Biology"},
"courses": [300, 305]
});
{
"_updatedAt": {
"$date": "2016-08-06T00:15:41.350Z"
}
}
You can also provide a session token if security is enabled for this collection:
var dbApiKey = "c33010af-f263-4443-9897-c2ffaf522956";
var token = "...";
var result = Collection.updateObject(dbApiKey, "Student", "57a52796e4b03647ddae32a5", {
"isTransferStudent": true,
"major": {"name":"Biology"},
"courses": [300, 305]
}, token);