gpt4 book ai didi

javascript - 使用 Parse Cloud Code 一次更新多个对象

转载 作者:行者123 更新时间:2023-12-02 15:58:35 25 4
gpt4 key购买 nike

我需要更新存储在类中的多个对象的特定字段。我可以从客户端执行此操作,但我不喜欢它处理额外带宽的想法。如何更新和保存在 Cloud Code 查询中迭代的对象?本质上,以下 Swift 方法的 JS 等价物是什么?

var query = PFQuery(className:"GameScore")
query.whereKey("playerName", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in

if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
// Update object here
}

// Save your changes to ALL objects
PFObject.saveAllInBackground()
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}

最佳答案

我不确定你到底想做什么,但这也许就是你正在寻找的:

Parse.Cloud.define("updateScores", function(request, response) {
var query = new Parse.Query("GameScore");
query.equalTo("playerName", "Sean Plott");
query.each(function (object) {
// Do something with object
object.save();
}).then(function (success) {
request.success("OK");
}, function(err) {
request.error(err);
});
});

关于javascript - 使用 Parse Cloud Code 一次更新多个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31393667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com