最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

网站源码admin19浏览0评论

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

将文档中的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);
发布评论

评论列表(0)

  1. 暂无评论