在Firestore中获取文档名称

编程入门 行业动态 更新时间:2024-10-27 18:19:53
本文介绍了在Firestore中获取文档名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我从一个集合中获取多个文档时,结果只是每个文档数据都有一个数组.

When I get several documents from a collection, the result is only an array with each doc data.

firestore.collection("categories").valueChanges().subscribe(data => { console.log(data); // result will be: [{…}, {…}, {…}] };

如何获取每个文档的名称?

How can I get the name of each doc?

理想的结果如下:

{"docname1": {…}, "docname2": {…}, "docname3": {…}}

推荐答案

当您需要访问其他元数据(例如文档的键)时,可以使用snapshotChanges()流方法.

When you need to access additional metadata like the key of your Document, you can use the snapshotChanges() streaming method.

firestore.collection("categories").valueChanges().map(document => { return document(a => { const data = a.payload.doc.data();//Here is your content const id = a.payload.doc.id;//Here is the key of your document return { id, ...data }; });

您可以查看文档以获得进一步的解释和例子

You can review the documentation for further explanation and example

更多推荐

在Firestore中获取文档名称

本文发布于:2023-10-23 22:24:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   文档   Firestore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!