【发布时间】:2020-06-02 07:54:15
【问题描述】:
我有一个使用 Firestore 的 Angular 应用程序。每当我查询集合中满足特定条件的文档时,返回的数组包含集合中的每个文档。我不明白为什么会发生这种情况,因为我是following the documentation。
调用组件中的集合
this.FirebaseService.getDocsByParam( 'versions', 'projectId', this.projectData.uid )
.then((snapshot) => {
var tempArray = [];
var docData;
snapshot.forEach((doc) => {
docData=doc.data();
docData.uid=doc.id;
tempArray.push(docData);
});
this.versionList = tempArray;
this.versionData = this.versionList[this.versionList.length-1];
this.initializeAll();
})
.catch((err) => {
console.log('Error getting documents', err);
});
Firebase 服务发出调用
getDocsByParam( collection, getParam:string, paramValue:string ) {
var docRef = this.afs.collection(collection, ref => ref.where(getParam, '==', paramValue));
return docRef.ref.get();
}
以下是版本集合的屏幕截图。它显示了一个返回的文档,它甚至没有必填字段。
【问题讨论】:
标签: javascript firebase google-cloud-firestore angularfire2