Delete objects without retrieving them

56 views
Skip to first unread message

mohamed belhassen

unread,
Jun 24, 2020, 6:22:39 AM6/24/20
to Back4App
Hi there,

I wonder why in Parse, we have to retrieve objects using find before deleting them. 
Is there a way to delete objects based on criteria of some fields of the object.
I am interested in the case where the app is not aware about the ID of the objects to delete.


nat...@back4app.com

unread,
Jul 3, 2020, 2:11:04 PM7/3/20
to Back4App
Hi Mohamed,

thanks for reaching out!

If you don't know the object Id that you would like to delete, at the moment, you need to search for the value in the database first before deleting it. As exemplified at the following code:

var query = new Parse.Query('table');
query
.equalTo('delete_me', 1);

query
.find().then(function(results) {
 
return Parse.Object.destroyAll(results);
}).then(function() {
 
// Done
}, function(error) {
 
// Error
});


If you are facing any problem, please let us know!

Regards,
Reply all
Reply to author
Forward
0 new messages