首页 > 解决方案 > 使用组合查询时 Firebase Firestore 返回空数组

问题描述

我正在尝试在同一个 firebase 查询中组合两个过滤器。当我尝试仅使用搜索查询时,它完美地工作并且与日期范围查询相同。但是当我结合这两个查询时,它返回一个空数组。我不明白为什么会这样。这是我的组合查询。它有什么问题。

export const getUsers = async (minDate:Date, maxDate:Date) => {
   
admin
   .firestore()
   .collection("users")
   .where("name", ">=", "abc")
   .where('name', "<=", "abc"+"~")
   .orderBy('name', "asc")
   .orderBy('createdAt')
   .startAt(admin.firestore.Timestamp.fromDate(new Date(minDate)))
   .endAt(admin.firestore.Timestamp.fromDate(new Date(maxDate)))
   .get()
   .then(async (DS) => {
                if ( DS ) {
                    const arr: any[] = [];

                   await DS.docs.forEach(doc=>{
                        arr.push(doc.data())
                    })
                    functions.logger.info(
                        "get successfully - ",
                        await DS.docs
                    );
                    
                    return arr;
                } else {
                    
                    throw new functions.https.HttpsError(
                        "invalid-argument",
                        ""
                    );
                }
            })
            .catch((error) => {
                throw new functions.https.HttpsError(
                    "invalid-argument",
                    error.message
                );
            });
}

我在云功能中使用firebase admin,并且所有索引都是由firebase建议的。

标签: node.jsgoogle-cloud-firestoregoogle-cloud-functionsfirebase-admin

解决方案


推荐阅读