Updating Entries in Parse with Geopoints

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) {

    // Set up to modify user data
    Parse.Cloud.useMasterKey();

    var recordsUpdated = 0;

    // Query for all objects with GeoPoint location null
    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) {
            // Set the job progress status
            status.message(recordsUpdated + " records updated.");
        }

        // Update to GeoPoint
        object.set("location", new Parse.GeoPoint(location));
        return object.save();
    }).then(function() {
        // Set the job success status
        status.success("Migration completed successfully.");
    }, function(error) {
        // Set the job error status
        console.log(error);
        status.error("Uh oh, something went wrong!");
    })
});
+4
source share
1 answer

According to the comments, your problem is that some members of the class do not have longitudeor latitude.

You can modify your request to process only those that have both values:

var query = new Parse.Query("Class");
query.doesNotExist("location");
query.exists("longitude");
query.exists("latitude");
query.each(function(object) {
    // etc

, , Parse.Promise.error(), .

+1

Source: https://habr.com/ru/post/1546437/


All Articles