gpt4 book ai didi

javascript - 解析: count of objects with pointer to another type object with given ID

转载 作者:行者123 更新时间:2023-11-28 00:08:27 25 4
gpt4 key购买 nike

我定义了一个 X 类型的 Parse 核心对象,它有一个指向另一个 Y 类型对象的指针作为其属性之一。定义了大约 1000 个 X 类型对象和大约 20 个 Y 类型对象。

我需要创建一个 JavaScript 查询,该查询将从 Y 类型对象的对象 ID 开始,并获取包含指向具有此对象 ID 的 Y 类型对象的指针的 X 类型对象的计数。

这对于传统的基于 SQL 的后端来说是一个非常简单的查询,但在 Parse 中我找不到解决方案。

最佳答案

您可以使用关系查询轻松完成此操作。假设您有一个 Y 类对象的本地实例,那么查询将如下所示

var ObjectX = Parse.Object.extend("X");
var query = new Parse.Query(ObjectX);
query.equalTo("objectYField", myObjectOfTypeY);
query.count({
success: function(count) {
// The count request succeeded. Show the count
},
error: function(error) {
// The request failed
}
});

来自 docs 的一个小警告虽然

Count queries are rate limited to a maximum of 160 requests per minute. They can also return inaccurate results for classes with more than 1,000 objects. Thus, it is preferable to architect your application to avoid this sort of count operation (by using counters, for example.)

关于javascript - 解析: count of objects with pointer to another type object with given ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117728/

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