我有大约600,000条记录,我通过数据上传器以CSV格式上传。我的经纬度列是分开的。我试图用这个脚本在云代码中修改类。它有时会更新,另一些时候会出现错误。有人能帮我写这个脚本吗?或者有没有一个我不知道的方法。
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!");
})
});发布于 2014-06-29 00:45:31
根据注释,您的问题是有些类成员没有longitude或latitude。
可以将查询更改为只处理同时具有两个值的查询:
var query = new Parse.Query("Class");
query.doesNotExist("location");
query.exists("longitude");
query.exists("latitude");
query.each(function(object) {
// etc然后,您不再需要检查它们是否为空,不再需要返回Parse.Promise.error(),因此不应该再命中错误。
https://stackoverflow.com/questions/24470403
复制相似问题