我似乎无法在Cloud函数中组合两个"where"子句(Firestore文档没有更新(。如果有人能指出我的错误,我将不胜感激。
return admin.firestore().collection('/events/')
// .where('data', '<', new Date()).where('published', '==', true) // Doesn't work (multiple)
// .where('data', '<', new Date()) // Works (single)
// .where('published', '==', true) // Works (single)
.get().then(
(result: any) => {
if (result.size > 0) {
result.forEach(async (doc: any) => {
await doc.ref.update({
'published': false,
})
await sgMail.send(msg);
})
}
提前感谢!
来自官方文档:
您只能对单个字段执行范围比较(<,<=,>,>=(,并且在复合查询中最多可以包含一个array_contents子句。但是,在您的情况下,要将相等运算符(==(与范围或数组包含子句(<、<=、>、>=或数组包含(组合,请确保创建复合索引