简体   繁体   English

是否可以再次查询Firestore中的对象数组中的对象字段?

[英]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: 在Firestore中有一些数据如下所示:

对象数组

My query: 我的查询:

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

returns no matches. 不返回匹配项。 Is such a query possible in Firestore? 在Firestore中可以进行这样的查询吗? @DougStevenson's answer suggests it wasn't possible a few months ago. @DougStevenson的回答表明,几个月前是不可能的。 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. 我能想到的唯一替代方法是将电话号码存储为平面数组(即,数组/ StringList ),以使其可搜索。

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. 您现在所拥有的将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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