I understand from this post that firestore queries don't currently provide for the following scenario. Given data like this:
somecollection/somedoc:
foos: [ { name:"foo" email:"foo@bar.com" }, ... ]
somecollection/someotherdoc:
foos: [ { name:"bar" email:"bar@foo.com" }, ... ]
I cannot write a query like:
FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"foos.email" isEqualTo:@"foo@bar.com"];
The advice in the other answer is to create a map of the array fields I wish to query, using the values as keys. Something like:
somecollection/somedoc:
foos: [ { name:"foo" email:"foo@bar.com" }, ... ]
emails: { "foo@bar.com": true, ... }
somecollection/someotherdoc:
foos: [ { name:"bar" email:"bar@foo.com" }, ... ]
emails: { "bar@foo.com": true, ... }
Now my query would be:
FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"emails.foo@bar.com" isEqualTo:@(YES)];
But this query returns no documents, owing to the fact I think, that an email address isn't good syntax for a map's key. Among other potential noise, it contains a dot .
which I fear looks to the FIRQuery
as a dereferencing operator.
Can someone explain how to query on emails in an array (or any other object that seems ill-suited as a key in map)?