首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Geopoints更新分析中的记录

用Geopoints更新分析中的记录
EN

Stack Overflow用户
提问于 2014-06-28 19:53:50
回答 1查看 907关注 0票数 4

我有大约600,000条记录,我通过数据上传器以CSV格式上传。我的经纬度列是分开的。我试图用这个脚本在云代码中修改类。它有时会更新,另一些时候会出现错误。有人能帮我写这个脚本吗?或者有没有一个我不知道的方法。

代码语言:javascript
复制
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's 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's success status
        status.success("Migration completed successfully.");
    }, function(error) {
        // Set the job's error status
        console.log(error);
        status.error("Uh oh, something went wrong!");
    })
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-29 00:45:31

根据注释,您的问题是有些类成员没有longitudelatitude

可以将查询更改为只处理同时具有两个值的查询:

代码语言:javascript
复制
var query = new Parse.Query("Class");
query.doesNotExist("location");
query.exists("longitude");
query.exists("latitude");
query.each(function(object) {
    // etc

然后,您不再需要检查它们是否为空,不再需要返回Parse.Promise.error(),因此不应该再命中错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24470403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档