Reputation: 151
I have an object which contains 50 entries in it. What I want to do is, I want to pick 10 of them RANDOMLY.
Data contains only id (from 1 to 50) and some string.
To achieve this, I made a list of integers at the size of object (50). Then shuffled it, like so:
[3, 28, 27, 21, 5, 35, 46, 34, 40, 14, 49, 44, 2, 24, 22, 38, 20, 41, 6, 15, 12, 29, 30, 43, 26, 4, 1, 23, 10, 45, 42, 8, 18, 36, 13, 48, 16, 32, 39, 47, 7, 33, 37, 0, 19, 31, 25, 9, 17, 11]
Then I took first 10 items from this random list .
[3, 28, 27, 21, 5, 35, 46, 34, 40, 14]
But the question is, how can I request the items of these ids from Parse in one call?
I could make a loop of calls but that would be too much requests.
What I have: Ids of objects. What I want: Corresponding string values at these id numbers.
Upvotes: 0
Views: 641
Reputation: 937
You will have to create a ParseQuery and then add the where clause:
Integer[] ids = {3, 5, 12, 23};
ParseQuery<ParseObject> query = ParseQuery.getQuery("YourObjectName");
query.whereContainedIn("yourObjectsIdField", Arrays.asList(ids));
query.findInBackground(new FindCallback<ParseObject>() {
void done(List<ParseObject> results, ParseException e) {
// enter code to execute after query has finished here
}
});
Upvotes: 1