Skip to content

Instantly share code, notes, and snippets.

@gngeorgiev
Created January 29, 2018 16:23
Show Gist options
  • Save gngeorgiev/aa34c11ad8d8cf6460c4b67d5b36b608 to your computer and use it in GitHub Desktop.
Save gngeorgiev/aa34c11ad8d8cf6460c4b67d5b36b608 to your computer and use it in GitHub Desktop.
Parse Installation deduplication - Cloud Code
Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {
var androidId = request.object.get("androidId");
if (!androidId) {
console.warn("No androidId found, save and exit");
return response.success();
}
var query = new Parse.Query(Parse.Installation);
query.equalTo("androidId", androidId);
query.ascending("createdAt");
query.find()
.then(results => {
return results.map(r => r.destroy());
})
.then(() => response.success())
.catch(err => response.error("Error: Can't query for Installation objects."));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment