简体   繁体   English

如何计算parse.com查询中数组值的数量?

[英]How to count number of array values in a parse.com query?

PFQuery *query1 = [PFUser query];
[query1 whereKey:@"array" containedIn:currentUserArray];

PFQuery *orderQuery = [PFQuery orQueryWithSubqueries:@[query1]];
[orderQuery orderByAscending:query1.count];

I know this code won't do the trick , but this is all I have so far. 我知道这段代码不会解决问题 ,但这是我到目前为止的全部。

Basically I'm doing a query on User class to see if any User's " array " is containedIn currentUser's array . 基本上,我正在对User类进行查询,以查看currentUser的 array中是否包含任何User的数组 ”。

As of right now, I can get all the users that have common array values, but I want to order the results from most common arrays to least common . 截至目前,我可以得到所有具有共同数组值的用户,但我要订购从最常见的阵列最不常见的结果。

I know you can countObjects in query, but I'm trying to count array values in objects in query. 我知道您可以在查询中计算对象,但是我正在尝试计算查询中对象的数组值。

How can I do this? 我怎样才能做到这一点? Will I have to go beyond Parse's documentation to accomplish this? 我是否需要超越Parse的文档才能完成此工作?

The answer is that you will need to store and maintain a count field. 答案是您将需要存储和维护一个计数字段。 You can use Cloud Code to keep the number updated. 您可以使用Cloud Code保持数字更新。

Read the help documentation on Cloud Code - Performing Actions After a Save , as it covers maintaining a count like you would need to. 阅读有关Cloud Code的帮助文档-保存后执行操作 ,因为它涵盖了维护所需的计数。

Once you have that in place you will have a field you can sort on. 将其放置到位后,您将可以在其中进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM