Hyder
Hyder

Reputation: 1173

Compare dictionary object with an Array in Parse.com - iOS

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?

Upvotes: 1

Views: 92

Answers (1)

danh
danh

Reputation: 62686

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.

Upvotes: 1

Related Questions