【问题标题】:Firestore query - assign repetitive query elements to variableFirestore 查询 - 将重复的查询元素分配给变量
【发布时间】:2022-01-24 02:40:53
【问题描述】:

我有很多 Firestore 查询。它们仅在一个元素上有所不同。是否可以将重复元素分配给变量?

firstQuery = query(productEventsCollection,
                orderBy("created", "desc"),
                where("productEventType", "==", eventType),
                where("created", ">=", startDate),
                where("created", "<=", endDate),
                where("productSKU", "==", prodSku),
                limit(queryLimit));

类似于:

firstQuery = query(VARIABLE,
                limit(queryLimit));

【问题讨论】:

    标签: javascript google-cloud-firestore


    【解决方案1】:

    您可以构建一个函数调用数组来构建您的查询,然后使用 spread syntax ... 调用 query() 函数,并将数组中的每个项目作为参数:

    const queryArgs = [productEventsCollection, orderBy("created", "desc"), where("productEventType", "==", eventType), where("created", ">=", startDate), where("created", "<=", endDate), where("productSKU", "==", prodSku)];
    const firstQuery = query(...queryArgs, limit(queryLimit));         
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多