1

I have a class that has a object type column, e.g.

          COLUMN 1
Row 1 :   {"gender":"male","name":"A"}
Row 2 :   {"gender":"female","name":"B"}
Row 3 :   {"gender":"male","name":"C"}

I need to get the rows whose objects for key name, in COLUMN1, matches the contents of my array ["A","B"]

So in may case, query should return ROW 1 and ROW 2.

I know this method but its for comparing array with a string column in Parse, as far as I know: [query whereKey:@"name" containsAllObjectsInArray:selectedParticipants];

How to compare my array with a dictionary column?

Hyder
  • 1,163
  • 2
  • 13
  • 37
  • why dont you just create an array with the values from the dictionary and put that array in the query? I know that Swift works that even if you do this it wont "create" an actual copy but a pointer to it so it is very fast even with 10 thousand of lines... – Mazel Tov Mar 30 '16 at 10:53

1 Answers1

1

One of the disadvantages of the object type in a parse.com collection is that it can only be queried for an exact match. The only way to do this under your current model is to qualify the query with the other columns to get back the smallest set that might match on the object criterion, then do the object matching on the client side.

If the collection has a lot of documents, and you want this to run fast, the better choice is to adjust the data model so the query-able properties in the embedded objects are their own columns...

       name (string) gender (string) otherStuff (object)
row0   "A"           "male"          { /* stuff we don't query on */ }
row1   "B"           "female"        { ... }
...

With that, you would use [query whereKey:@"name" containedIn:@[@"A", @"B"]] to qualify the query. Notice this is not containsAllObjectsInArray, which is how to test an array property.

danh
  • 62,181
  • 10
  • 95
  • 136