【发布时间】:2020-08-17 18:39:54
【问题描述】:
这是我的 firestore 数据库中的 User 集合:
我正在尝试使用下面的方法只返回Users where isMechanic === false:
private _mechanics = new BehaviorSubject<User[]>([]);
get mechanics() {
return this._mechanics.asObservable();
}
return of(
firebase.firestore().collection("users").where("isMechanic", "==", "false")
.get()
.then((docs) => {
const data = []
docs.forEach((doc) => {
data.push(doc);
});
this._mechanics.next(data)
console.log('Mechanics in UsersService:', this._mechanics);
console.log('Mechanics in UsersService:', this.mechanics);
}).catch((err) => {
console.log(err);
})
);
当前没有记录在调用此方法时,控制台会记录一个空数组。因此,即使(根据屏幕截图)isMechanic 是 false 的记录,也不会返回任何记录。
谁能告诉我这个功能需要做哪些改变才能按预期工作?
【问题讨论】:
-
首先,
isMechanic在用户中在哪里? -
它不起作用,因为
isMechanic不是数组中对象的属性。您是否尝试过查看嵌套属性以查看该属性的位置?例如,在metadata中。我不使用 Firestore,但我想这应该记录在官方文档中?
标签: angular typescript firebase ionic-framework google-cloud-firestore