I have about 600,000 records that I uploaded through a CSV data downloader. Columns of longitude and latitude are separate. I am trying to change a class in cloud code using this script. It is updated sometimes, and then at another time an error appears. Can someone help me with this script or is there a way to do this that I don't know about.
Parse.Cloud.job("CreatePoints", function(request, status) {
Parse.Cloud.useMasterKey();
var recordsUpdated = 0;
var query = new Parse.Query("Class");
query.doesNotExist("location");
query.each(function(object) {
var location = {
latitude: object.get("latitude"),
longitude: object.get("longitude")
};
if (!location.latitude || !location.longitude) {
return Parse.Promise.error("There was an error.");
}
recordsUpdated += 1;
if (recordsUpdated % 100 === 0) {
status.message(recordsUpdated + " records updated.");
}
object.set("location", new Parse.GeoPoint(location));
return object.save();
}).then(function() {
status.success("Migration completed successfully.");
}, function(error) {
console.log(error);
status.error("Uh oh, something went wrong!");
})
});
source
share