How can I retrieve, edit and save objects in 2 queries?

Hello,

I can’t find mass update example in docs.

How can I get array/object containing data, iterate through elements, change values and then save them at once?

const fanaticsObject = Parse.Object.extend("ItemsCreated");
const query = new Parse.Query(fanaticsObject);
query.equalTo("to", "1122");
const results = await query.find({useMasterKey: true});
//Do stuff with results....
results.save() // Definitely will not work

I think that you can iterate every item from results and call save on each item where you made an update.

So query will run “results.lenght” times. I am a MySQL guy, so I think this is not problem at all for MongoDB and my algorithm of seeing problem is incorrect at this point :smile:

    query.find().then(function(results) {
        _.each(results, function(result) {
            var firstname = result.get("firstname") || "";
            var lastname = result.get("lastname") || "";
            result.set("fullname", (firstname + " " + lastname).trim());
        });
        return Parse.Object.saveAll(results);
1 Like