我有一个角度应用程序,其中我使用AngularFire ("@angular/fire": "7.4.1)和Firebase ("firebase": "9.8.4")查询具有特定约束的Firestore中的集合:
import { collection, Firestore, onSnapshot, query } from '@angular/fire/firestore';
import { QueryConstraint, Unsubscribe, where } from 'firebase/firestore';
@Injectable({
providedIn: 'root',
})
export class DataService {
constructor(private firestore: Firestore) {
this.listen();
}
private listen() {
const constraints: QueryConstraint[] = [where('lastUpdated', '>=', lastAppStart), where('recommended', '==', true)];
const ref = query(collection(this.firestore, `all`), ...constraints);
onSnapshot(ref, async (snapshot) => {
// ...
});
}
}一旦我听到这个查询,它就会出现以下错误:
ERROR: FirebaseError: [code=invalid-argument]: Expected type 'Va', but it was: a custom Pa object这个错误似乎是指我要传递的约束。一旦我删除它们,查询就会成功,不会出现任何错误。
发布于 2022-08-31 19:21:07
问题是,我从AngularFire和Firebase混合了进口。要解决这个问题,重要的是合并它们并从@angular/fire导入所有内容:
import { collection, Firestore, onSnapshot, query, QueryConstraint, Unsubscribe, where } from '@angular/fire/firestore';https://stackoverflow.com/questions/73560934
复制相似问题