简体   繁体   中英

Is it possible to query againt an object field in an array of objects in Firestore?

Have some data in Firestore that looks like this:

对象数组

My query:

db().collection("contactLists").whereArrayContains("contacts.id", "+911122334455");

returns no matches. Is such a query possible in Firestore? @DougStevenson's answer suggests it wasn't possible a few months ago. Is that still the case? Am I perhaps specifying the query incorrectly?

The only alternative I can think of is to store the phone numbers as a flat array (ie, an array/ List of String s) to make them searchable.

With array queries, you have to call out the name of a document field that is itself an array type. You can't call out the name of an object field contained within the array.

You also need to be searching for the exact contents of the array elements in their entirety, and not just individual properties on objects stored in the array.

If you need to search documents by some string in an array, the array needs to only contain only the strings to search. What you have now won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM