sample:
const cert = await new Parse.Query("Some1").equalTo('p1', request.params.p1).find({
useMasterKey: true
});
cert[0].save({
p2: request.params.p2,
p3: request.params.p3
});
only update one. how to update multi-object?
api: https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#.saveAll
try this
//update your objects here
cert[0].p2 = request.params.p2;
cert[0].p3 = request.params.p3;
cert[1].p2 = ..
cert[1].p3 = ..
...
//update all objects at once
Parse.Object.saveAll(cert, { useMasterKey: true })
.then((list) => {
// All the objects were saved.
}, (error) => {
// An error occurred while saving one of the objects.
console.log(error);
});
how to change multiple object's element values? [p2 & p3]
Sorry I thought you wanted to save multiple objects at the same time.
So you want to change attributes p2 and p3 of all the objects returned by the find() method?
You could try:
//update your objects here
cert.forEach((item, index) => {
item.p2 = request.params.p2;
item.p3 = request.params.p3;
});
//update all objects at once
Parse.Object.saveAll(cert, { useMasterKey: true })
.then((list) => {
// All the objects were saved.
}, (error) => {
// An error occurred while saving one of the objects.
console.log(error);
});
Let me know if this was what you wanted.
Thank you. can you help me with this issue? #6622
One thing I am thinking about is if the objects in cert are of type Parse.Object, then you might need to do this to update the p2 and p3:
//update your objects here
cert.forEach((item, index) => {
item.set('p2', request.params.p2);
item.set('p3', request.params.p3);
});
or
//update your objects here
cert.forEach((item, index) => {
item.attributes.p2 = request.params.p2;
item.attributes.p3 = request.params.p3;
});
I will check your other issue :)
OK, thank you for your help.
so....if I have one million data or more data, need circle one million times?
I am not sure what you are trying to do here, but to update millions of records at the same time, I think it is better if you can make some kind of database function (like stored procedure), and have your parse-server cloud code use that function.
ok, thank you.
This works but throws error :
`UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. `
What is the correct and safe way of using SaveAll in cloud code.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Sorry I thought you wanted to save multiple objects at the same time.
So you want to change attributes p2 and p3 of all the objects returned by the find() method?
You could try:
Let me know if this was what you wanted.