集合中所有ID的Firebase Firestore列表

时间:2018-11-05 17:02:27

标签: javascript firebase google-cloud-firestore

Google Firebase似乎很难绕开我的脑袋……从集合中获取文档及其数据没有问题,但是当我尝试简单地获取集合中所有ID的列表时,我无法确定通话的外观。我尝试搜索信息,但没有成功。

enter image description here

我在服务组件中声明了一个函数,如下所示:

getCollRegistrationNumbers(): firebase.firestore.CollectionReference {
  return firebase.firestore().collection(`storedItems`);
}

然后例如在我应用的“搜索”页面上,我正在从组件中调用该函数,但是无论我如何尝试,它都将返回空。

鉴于上面的服务功能,我应该如何完成下面的代码以仅混合ID列表?

this.fireStore.getCollRegistrationNumbers().get()
  .then(snapshot => {....})

2 个答案:

答案 0 :(得分:2)

看看您的文档以斜体显示的方式:这意味着在控制台中,这些文档仅作为一个或多个子集合的“容器”出现,而不是“真实”文档。 / p>

答案 1 :(得分:0)

只需执行以下操作:

this.fireStore.getCollRegistrationNumbers().get()
.then(querySnapshot => {
    querySnapshot.forEach(doc => {
        console.log(doc.id);
    });
});

有关更多详细信息,请参见有关如何检索集合hereQueryDocumentSnapshot here中所有文档的文档,这些文档“提供与{{1 }}”。

相关问题