字段"/>
将文档中的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数据设置为单独的字段
发布评论