2
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.

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?

1 Answer 1

1

The answer is that you will need to store and maintain a count field. You can use Cloud Code to keep the number updated.

Read the help documentation on Cloud Code - Performing Actions After a Save, as it covers maintaining a count like you would need to.

Once you have that in place you will have a field you can sort on.

Sign up to request clarification or add additional context in comments.

4 Comments

Bear in mind that under Parse's new pricing model, save hooks can be terminated if they run longer than three seconds. That sounds like a long time but Parse sometimes inexplicably takes this long to run a minimal hook and your counts are wrong.
@RogerNolan I simply quoted what Parse recommend in their documentation, what do you mean by "and your counts are wrong"? If the save hook is terminated, if you mean the save has finished but the afterSave hasn't updated the count, then use beforeSave and the timeout error means to try the save again (the timeout bugs me too!). I have had to create a tryAtMost(times, anonFunction) method so my save buttons can try a couple of times if needed before showing an error to the user.
See here: groups.google.com/forum/#!topic/parse-developers/1GOv37oTY2k and specifically this defect developers.facebook.com/bugs/1507064772916218 where Parse development contradict their own documentation and say "To make this more reliable we suggest updating both objects directly from the client, or from a cloud-code function with a 15s limit" i.e. saveHooks are useless.
If done in beforeSave with auto-retry it becomes more useful (when it works, on a quiet day), but I can see how that chews up extra requests and isn't scalable. I fear Parse is become less and less viable a solution other than for quick startup of ideas :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.