更新时间:2023-02-05 15:21:46
通过链接查询中的条件来查找匹配多个条件的文档会很诱人:
It would be tempting to to look for documents that match multiple conditions, by chaining the conditions in the query:
db.collection("Fruits")
.whereField("vitamins", arrayContains: "B6")
.whereField("vitamins", arrayContains: "C")
但是关于复合查询的文档表明您不能当前在单个查询中有多个 arrayContains 条件.
But the documentation on compound queries suggests that you cannot currently have multiple arrayContains conditions in a single query.
所以,用你今天拥有的东西是不可能的.考虑使用映射结构而不是数组:
So, it is not possible with what you have today. Consider instead using a map structure instead of an array:
Fruits:
Banana:
title: "Banana"
vitamins: {
"potassium": true,
"B6": true,
"C": true
}
然后你可以这样查询:
db.collection("Fruits")
.whereField("vitamins.B6", isEqualTo: true)
.whereField("vitamins.C", isEqualTo: true)