【问题标题】:Firestore Set Data in a document as separate fieldsFirestore 将文档中的数据设置为单独的字段
【发布时间】:2020-05-11 03:01:09
【问题描述】:

我从 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,
         ...
         })
});

【问题讨论】:

    标签: node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    只需传递data 而不用大括号括起来。

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

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2019-06-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多