如何进行此 Firestore 查询?
How can I make this Firestore query?
我是Firestore新手,需要查询。我有这个数据库结构:
{
"businesses": {
"1" : {
"name": "bla",
"employees": {
"1" : {
"name": "Juan",
"schedules": {
"1": {
"scheduleId" : "72",
"from": "21/08/2020"
}
}
},
"schedules": {
"72": {
//some properties
}
}
}
}
}
}
给定 businessId
和 scheduleId
,我需要获取分配了 scheduleId
的所有企业员工。
我试过这个:
export async function getEmployeesWithSchedule(businessId: string, scheduleId: string): Promise<Employee[]> {
const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
.where("schedules.scheduleId", "==", scheduleId)
.get()).docs;
//extract results
}
但我没有得到任何结果。我该如何查询?
试试下面的 where
子句。您应该只取回文档,其中 schedules
映射包含键值对 scheduleId
和 non-null
值:
const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
.where(`schedules.${scheduleId}`, "!=", null)
.get()).docs;
我是Firestore新手,需要查询。我有这个数据库结构:
{
"businesses": {
"1" : {
"name": "bla",
"employees": {
"1" : {
"name": "Juan",
"schedules": {
"1": {
"scheduleId" : "72",
"from": "21/08/2020"
}
}
},
"schedules": {
"72": {
//some properties
}
}
}
}
}
}
给定 businessId
和 scheduleId
,我需要获取分配了 scheduleId
的所有企业员工。
我试过这个:
export async function getEmployeesWithSchedule(businessId: string, scheduleId: string): Promise<Employee[]> {
const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
.where("schedules.scheduleId", "==", scheduleId)
.get()).docs;
//extract results
}
但我没有得到任何结果。我该如何查询?
试试下面的 where
子句。您应该只取回文档,其中 schedules
映射包含键值对 scheduleId
和 non-null
值:
const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
.where(`schedules.${scheduleId}`, "!=", null)
.get()).docs;