无法在 Parse Cloud Code afterSave 方法中查询关系计数

Can't query relation count in Parse Cloud Code afterSave method

我在 Parse 中有一个名为 Message 的对象 class,它与许多 PFInstallation 对象有关系 installations。我使用此关系来跟踪当前哪些安装具有每个 Message 对象的本地副本。

我想在每次保存 Message 对象时检查每个 Message 的 installations 关系中是否有非零数量的 PFInstallations,为此我在 Cloud Code 中使用以下方法:

Parse.Cloud.afterSave("Message", function(request) {
    var message = request.object;
    var query = message.relation("installations").query();
    query.count({
        success: function(count) {
            console.log("count = "+count);
        },
        error: function(error) {
            console.error("Could not count installations for Message": "+error);
        }
    });
});

但是我收到以下错误消息:

v8 after_save triggered for Message for user <redacted>:
  Input: {"object":{"createdAt":"2015-08-10T18:41:21.041Z","installations":{"__type":"Relation","className":"_Installation"},"isRead":0,"objectId":"N88D2m1bqB","recipient":"recipient@domain.com","sendDate":{"__type":"Date","iso":"2015-08-10T18:40:15.047Z"},"sender":"sender@domain.com","text":"v8","updatedAt":"2015-08-10T18:41:21.041Z"}}
  Result: Success
I2015-08-10T18:41:22.305Z]Could not count installations for Message: [object Object]

我不知道为什么会收到此错误消息或错误 [object Object] 的含义。在其他常规 Cloud Code 方法中,我已经能够使用上面示例中的查询来计算关系中对象的数量。

请让我知道我可以提供哪些其他信息或说明来帮助回答这个问题。

您需要使用万能钥匙来阅读安装table。尝试在 运行 您的 find() 查询之前调用 Parse.Cloud.useMasterKey()