我需要从Class中获取超过1000个元素。
所以我尝试了this topic上的建议,但是有些东西没有正常工作,并且已经花了一整天的时间来寻找解决方案。
Parse.Cloud.define("getFollow", function(request, response) {
var following = [];
var user = request.params.user;
user.fetch().then(function(result) {
if (!result.get('following')) {
following = getFollowing({
'user': user
});
}
}).then(function() {
response.success(following);
}, function(error) {
response.error(error);
});
});
function getFollowing(request) {
var count = 0;
var skip = request.skip || 0;
var limit = 1000;
var following = request.following || [];
var Follow = Parse.Object.extend('follow');
var query = new Parse.Query(Follow);
query.limit(limit);
query.ascending('objectId');
query.skip(skip * limit);
query.equalTo('followers', request.user);
query.find().then(function(results) {
skip+= 1;
count = results.length;
/* I can't see any DEBUG, seems nothing is queried */
console.log('[DEBUG] Check <count>: ' + count);
return Parse.Promise.when(results.map(function(result) {
following.push(result.get('followed'));
}));
}).then(function() {
if(count >= limit) {
following = getFollowingUsers({
'user': request.user,
'skip': skip,
'following': following
});
}
}).then(function() {
return following;
}, function(error) {
return error;
});
}
我尝试了许多此代码的变体,尝试返回查询的第一个结果,而不是集合。我也尝试删除所有约束,但即便如此,我的查询似乎也没有运行。
我还尝试使用Cloud.code函数仅使用Parse.Cloud递归进行此操作,但如果我这样做,我将收到消息对Cloud Code的递归调用太多 < / p>
我对这个逻辑做错了什么?