iOS Parse.com内部查询不会获取所有对象 [英] iOS Parse.com inner query doesn't fetch all objects
问题描述
我在使用parse.com内部查询时遇到麻烦。
这是我的代码。
I am getting trouble with parse.com inner query using. Here is my code.
PFQuery *innerQuery = [PFUser query];
[innerQuery whereKey:@"deactive" equalTo:[NSNumber numberWithBool:NO]];
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
[query orderByDescending:@"voteCount"];
[query setLimit:1];
[query whereKey:@"user" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray objects, NSError error) {
//some code
}];
这是一个问题。
内部查询最大限制计数在Parse.com中也是1000。
在我的代码中,在User类中检索1000个对象并在它们之间执行查询。
如果用户数超过1000,则其他用户休息不在内部查询中。
所以我无法获得它的voteCount属性最大的post对象。
Here is a problem. Inner query max limit count is 1000 as well in Parse.com. In my code, after retrieving 1000 objects in User class and execute query among them. If user count exceeds 1000, then rest other users are out of inner query. so I can't get post object which it's voteCount property is largest.
我该如何解决?
Parse是不可能的?
How can I resolve it? Is it impossible on Parse?
推荐答案
您需要在完成块内重新启动查询。
You need to restart a query inside your completion block.
如果您有1000个结果,我们假设有更多要获取并使用新参数执行另一个查询,跳过
。 Skip
与您所知道的完全相同,但跳过
X的第一个结果。
If you have 1000 results, we assume that there is more to fetch and do another query with a new parameter, the skip
. Skip
does the exact same as what you know but will skip
the X first results.
所以你的限制
为1000,结果
为1000,并且是新的要查询查询
。
So you have your limit
of 1000, a result
of 1000, and a new query
to make.
您必须提供限额
值为跳过
值,因此您跳过第二批完全相同的数字(通常只是最大值1000)。
You must give your limit
value to your skip
value, so you skip exactly the same number (usually just the max, 1000) for your second batch.
您重复此操作,直到结果
计数为<超过1000,这意味着没有更多的对象可以获取。
You repeat this until your result
count is < than 1000, which means there aren't any more objects to fetch.
设置跳过值与设置限制相同。
Setting the skip value is the same as setting the limit.
[query setLimit:1000];
[query setSkip:1000];
或者如果你喜欢动态
[query setLimit:1000];
[query setSkip:query.limit];
编辑:如果您不需要所有信息,只需要最重要的信息(通常只是最新的日期),然后您可以简单地对您的查询进行排序。
EDIT : If you don't need all information but only the most important one (which is usually just the latest in date), then you can simply sort your query.
[query orderByAscending:@"createdAt"]; //or descending, or updatedAt, or your own fields
您还可以使用谓词或更多排序描述符减少请求的大小。
You can also use predicates or more sort descriptors to reduce the size of your request.
这篇关于iOS Parse.com内部查询不会获取所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!