我想在google云firestore中查询具有特定字段的对象数组中的对象,我的集合结构如下:
...
{
name: "shoes 1",
amount:150,
productors: [
{
id : "a001",
name : "productor 1"
},
{
id: "a002",
name: "productor 2"
}
...
]
...
}
{
name: "shoes 2",
amount:80,
productors: [
{
id : "a002",
name : "productor 2"
},
{
id: "a001",
name: "productor 1"
}
...
]
...
}
...我想查询这个集合,以获得在productors数组中的所有文档,produtor的id = e001。
我在nodejs环境中工作,使用firestore-admin-sdk
发布于 2019-08-15 21:31:00
这在Cloud Firestore中是不可能实现的。不能查询数组中对象的属性。您只能查询数组中某一项(完整对象)的整个值。
对于这个查询,您将需要一个单独的字段来查询,可能是只包含您想要查找的id值的数组。为此,您可以使用array-contains type query。
https://stackoverflow.com/questions/57510375
复制相似问题