将文档中的Firestore数据设置为单独的字段

编程入门 行业动态 更新时间:2024-10-10 10:27:03

将文档中的Firestore数据设置为单独的<a href=https://www.elefans.com/category/jswz/34/1771443.html style=字段"/>

将文档中的Firestore数据设置为单独的字段

我从firestore中的文档中获取多个字段,然后使用数据将相同的fields从该文档设置为另一个文档。一个文档中有很多字段。不写每个字段名称怎么办?

db.collection('sourceCollection').doc('sourceDoc').get().then( snap => {

    const data = snap.data()
    //from what I see this is an array now with fields in it

        db.collection('newCollection').doc('newDoc').set({
        //What do I put here so I can set the content of data as separate field in the newDoc 

        //if I do the following I get an array field called `data` within the new doc which is not what I want; I need the content of the `data` to be SEPARATE fields in the newDoc

         data

        //I also dont want to write each field because there are too many so the following wouldn't work for me: 
        fieldName: data.sourceDocFieldValue,
         ...
         })
});
回答如下:

只需传递data,不要将其放在花括号中。

db.collection('newCollection').doc('newDoc').set(data);

更多推荐

将文档中的Firestore数据设置为单独的字段

本文发布于:2024-05-07 10:13:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   设置为   文档   数据   Firestore

发布评论

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

>www.elefans.com

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