在 AngularFire 中查询集合时不能使用 "not equal" 运算符
Cannot use the "not equal" operator when querying for a collection in AngularFire
我正在尝试从 Firebase 中提取一个与用户无关的集合。到目前为止,我已经成功查询了用户的集合,但我似乎无法使用 !=
运算符获取与用户无关的集合。
这是我的代码:
// Does not work!
eventCollection: AngularFirestoreCollection<Event> = this.angularFirestore.collection("events", ref =>
ref.where("uid", "!=", this.firebaseAuth.auth.currentUser.uid)
);
eventCollection$: Observable<Event[]> = this.eventCollection.valueChanges();
// Works!
myCollection: AngularFirestoreCollection<Event> = this.angularFirestore.collection("events", ref =>
ref.where("uid", "==", this.firebaseAuth.auth.currentUser.uid)
);
myCollection$: Observable<Event[]> = this.myCollection.valueChanges();
抛出的错误是:
ERROR in src/app/event/events.service.ts(35,22): error TS2345: Argument of type '"!"' is not assignable to parameter of type 'WhereFilterOp'.
我试图寻找对应于 !=
的逻辑运算符,但似乎找不到。
如有任何帮助,我们将不胜感激!
It looks like 没有 !=
运算符。我不熟悉 Firebase,但也许您可以对 <
和 >
进行单独查询并合并结果?或者因为你也想要相同的结果,只做一个不带 where
的查询并自己分开相等和不相等的结果?
根据 Firestore doc:
Queries with a != clause. In this case, you should split the query into a greater-than query and a less-than query. For example, although the query clause where("age", "!=", "30") is not supported, you can get the same result set by combining two queries, one with the clause where("age", "<", "30") and one with the clause where("age", ">", 30).
因此您必须同时比较“<”和“>”条件
eventCollection: AngularFirestoreCollection<Event> =
this.angularFirestore.collection("events", ref =>
ref.where("uid", ">", this.firebaseAuth.auth.currentUser.uid)
.where("uid", "<", this.firebaseAuth.auth.currentUser.uid)
);
我正在尝试从 Firebase 中提取一个与用户无关的集合。到目前为止,我已经成功查询了用户的集合,但我似乎无法使用 !=
运算符获取与用户无关的集合。
这是我的代码:
// Does not work!
eventCollection: AngularFirestoreCollection<Event> = this.angularFirestore.collection("events", ref =>
ref.where("uid", "!=", this.firebaseAuth.auth.currentUser.uid)
);
eventCollection$: Observable<Event[]> = this.eventCollection.valueChanges();
// Works!
myCollection: AngularFirestoreCollection<Event> = this.angularFirestore.collection("events", ref =>
ref.where("uid", "==", this.firebaseAuth.auth.currentUser.uid)
);
myCollection$: Observable<Event[]> = this.myCollection.valueChanges();
抛出的错误是:
ERROR in src/app/event/events.service.ts(35,22): error TS2345: Argument of type '"!"' is not assignable to parameter of type 'WhereFilterOp'.
我试图寻找对应于 !=
的逻辑运算符,但似乎找不到。
如有任何帮助,我们将不胜感激!
It looks like 没有 !=
运算符。我不熟悉 Firebase,但也许您可以对 <
和 >
进行单独查询并合并结果?或者因为你也想要相同的结果,只做一个不带 where
的查询并自己分开相等和不相等的结果?
根据 Firestore doc:
Queries with a != clause. In this case, you should split the query into a greater-than query and a less-than query. For example, although the query clause where("age", "!=", "30") is not supported, you can get the same result set by combining two queries, one with the clause where("age", "<", "30") and one with the clause where("age", ">", 30).
因此您必须同时比较“<”和“>”条件
eventCollection: AngularFirestoreCollection<Event> =
this.angularFirestore.collection("events", ref =>
ref.where("uid", ">", this.firebaseAuth.auth.currentUser.uid)
.where("uid", "<", this.firebaseAuth.auth.currentUser.uid)
);