【问题标题】:How to access a single field in firebase doc in ionic app [duplicate]如何在离子应用程序中访问firebase doc中的单个字段[重复]
【发布时间】:2019-09-15 12:29:04
【问题描述】:

我需要在不下载整个文档的情况下访问 firebase 文档中的单个字段。

用例: 我在 firebase 中有一个 cmets 页面和一个 cmets 集合。我需要知道那里有多少 cmets 而无需全部下载。有一个带有commentCount 字段的文档,每次发布新评论时都会更新,还有一个包含所有cmets 的数组。我想访问字段 commentCount 并读取它的值。

this.angularFireStore.firestore.collection('comments/' + id + '/commentCount').get().then(col => {
      console.log(col);
    });

我试过这个,但它返回一个未定义的。 我怎样才能做到这一点?

【问题讨论】:

标签: javascript firebase google-cloud-firestore


【解决方案1】:

我的假设是commentCount 不是一个列表,因此它必须是Document 而不是Collection

试试这个:

this.angularFireStore.firestore.document('comments/' + id).valueChanges()
 .subscribe(comment => console.log(comment.commentCount));

另外,我不会将评论计数放在您的comments 列表中,如果您删除此特定评论会怎样?

【讨论】:

    猜你喜欢
    • 2021-08-06
    • 1970-01-01
    • 2014-08-12
    • 2013-11-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多