从集合中获取所有文档 firebase angular/typescript
Get all the documents from a collection firebase angular/typescript
大家好,我正在查看 firebase 的官方网站如何从集合中检索所有文档,但它只给了我 1 个,它不是第一个也不是最后一个,而是在中间的某个地方,它总是同一个对象,我不明白为什么会这样。你能检查一下,也许看看我做错了什么吗?我总是收到文件:“companion_live”
private firestore: AngularFirestore;
constructor(private routingService: RoutingService, firestore: AngularFirestore) {
this.firestore = firestore;
}
async ngAfterViewInit() {
const citiesRef = this.firestore.firestore.collection('user');
const snapshot = await citiesRef.get();
snapshot.forEach((doc) => {
this.allTruckRoute.push(doc.id);
});
if (this.allTruckRoute.length > 0) {
this.allTruckRoute.forEach(route => this.trucks.push({id: route, selected: false} as SelectedTrucks));
}
}
这是我的模式的样子:
您只能获得一份文档,因为用户集合中只有一份实际文档。您看到的斜体文件根本不是实际文件。它们只是具有子集合的缺失文档的占位符。如果您单击那个“丢失”的文档,您将看到它没有字段,但您可以进一步导航到它的嵌套子集合。当它们的子集合被全部删除时,这些丢失的文档将从控制台中消失。
目前唯一的文档是“companion_live”,因此这是您从用户查询中获得的唯一文档。
另请参阅:
- Why are non auto-generated document Ids are in italics in Firestore console?
- Firestore DB - documents shown in italics
大家好,我正在查看 firebase 的官方网站如何从集合中检索所有文档,但它只给了我 1 个,它不是第一个也不是最后一个,而是在中间的某个地方,它总是同一个对象,我不明白为什么会这样。你能检查一下,也许看看我做错了什么吗?我总是收到文件:“companion_live”
private firestore: AngularFirestore;
constructor(private routingService: RoutingService, firestore: AngularFirestore) {
this.firestore = firestore;
}
async ngAfterViewInit() {
const citiesRef = this.firestore.firestore.collection('user');
const snapshot = await citiesRef.get();
snapshot.forEach((doc) => {
this.allTruckRoute.push(doc.id);
});
if (this.allTruckRoute.length > 0) {
this.allTruckRoute.forEach(route => this.trucks.push({id: route, selected: false} as SelectedTrucks));
}
}
这是我的模式的样子:
您只能获得一份文档,因为用户集合中只有一份实际文档。您看到的斜体文件根本不是实际文件。它们只是具有子集合的缺失文档的占位符。如果您单击那个“丢失”的文档,您将看到它没有字段,但您可以进一步导航到它的嵌套子集合。当它们的子集合被全部删除时,这些丢失的文档将从控制台中消失。
目前唯一的文档是“companion_live”,因此这是您从用户查询中获得的唯一文档。
另请参阅:
- Why are non auto-generated document Ids are in italics in Firestore console?
- Firestore DB - documents shown in italics