Firestore + Cloud Functions:多个条件子句

我似乎无法在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);
      })
    }

谢谢!

geiwoaidechibang 回答:Firestore + Cloud Functions:多个条件子句

来自 Official Documentation

  

您只能在单个字段上执行范围比较(,> =),并且在复合查询中最多可以包含一个array_contains子句。但是,在您的情况下,要将相等运算符(==)与range或array-contains子句(,> =或array-contains)组合,请确保创建一个composite index

本文链接:https://www.f2er.com/3124003.html

大家都在问