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:"[email protected]" }, ... ]
somecollection/someotherdoc:
foos: [ { name:"bar" email:"[email protected]" }, ... ]
I cannot write a query like:
FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"foos.email" isEqualTo:@"[email protected]"];
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:"[email protected]" }, ... ]
emails: { "[email protected]": true, ... }
somecollection/someotherdoc:
foos: [ { name:"bar" email:"[email protected]" }, ... ]
emails: { "[email protected]": true, ... }
Now my query would be:
FIRCollectionReference *ref = [defaultFirestore collectionWithPath:@"/somecollection"];
FIRQuery *query = [ref queryWhereField:@"[email protected]" 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)?