如何在解析中获取云代码中的行数

How to get rows count in Cloud Code in Parse

本文关键字:代码 获取      更新时间:2023-09-26

我试过这个代码:我一直在获得成功/错误没有被调用。

Parse.Cloud.beforeSave("Offer", function(request, response) {
var duplicationQuery = new Parse.Query("Offer");
console.log(duplicationQuery.count);
});

然后我尝试了这个:

Parse.Cloud.beforeSave("Offer", function(request, response) {
var duplicationQuery = new Parse.Query("Offer");
duplicationQuery.count()
{
    success: function(httpResponse) {
    console.log(httpResponse.text);
    response.success(httpResponse.text);
    console.log("Row count:   "+duplicationQuery.count);
},
     error: function(httpResponse) {
     console.error('Request failed with response code ' + httpResponse.status);
     response.error('Request failed with response code ' + httpResponse.status); 
 }
}
});

我想我被不恰当的语法卡住了。有人能帮我吗?

我会说远离计数查询,因为它们效率低下。只需执行find查询并使用结果的length属性获取计数。

var duplicationQuery = new Parse.Query("Offer");
duplicationQuery.limit(1000); // max limit
duplicationQuery.find().then( function(results) {
    console.log(results.length);
});

还要记住,在任何查询中可以获得的最大记录数都限制为1000。