Does anybody know a way of updating multiple rows according to a given condition using the Parse.com REST API?
Imagine a class "Location" with several locations. Each item has a column "status" that holds an enum string value like "ok" or "error".
I would like to do something that can be done in a MongoDb somehow like this
db().find(query).update({status: "ok"})
In Words:
"Find all locations that match my query and then update the status to Ok".
There's nothing written about it in the Parse.com REST API Batch Operations Documentation and I doubt that Parse.com supports this. Parse.com supports batch operations, but obviously not if they're bound to a condition.
I'm not looking for the find-all-items-and-then-update-them-item-by-item-way, as this takes way too long, we're talking about tenthousands items.
There is no way to do that in one step. The closest operation to what you are looking for is the
saveAll
function. JS API ReferenceHere is the description:
Example usage:
With this operation, you will still have to query for the objects, iterate through them and update the values, then call
saveAll
on the list of updated objects.There has been a bit of confusion around the
saveAll
operation -- in particular, how many API requests it uses. This uncertainly is due to the fact that Parse has changed how they bill API requests and what was once true for this operation is no longer.Per this link:
This is no longer true. In April 2014, Parse changed their pricing model to the requests per second metric, but later that year Parse also changed how batch API requests were counted since developers started to exploit batch operations.
Here is an excerpt of an official Parse statement on the matter:
Using the
saveAll
operation today will result in 1 API request per object in the list, effectively callingsave
for each individual object.Presently, there is no way to avoid having to call save on each of the modified objects. Hopefully this is something that Parse will consider adding in the future.