云函数如何一次性如何一次性添加字段和数组?

小程序 文章 2021-03-23 18:43 451 0 全屏看文

AI助手支持GPT4.0

云函数如何一次性如何一次性添加字段和数组?How do cloud functions add fields and arrays all at once?

云函数如何一次性如何一次性添加字段和数组?

await db.collection("service_collection").add({

      data: {

        openid,

        userInfo,

        BlogGroup: _.push([collData])

      }

    })

这样写多了莫名其妙多了三个字段,还挺麻烦的


await db.collection("service_collection").doc(openid).update({

      data: {

        openid,

        userInfo,

        BlogGroup: _.push([collData])

      }

    })

这样写只有存在该数据才有效:

有哪位大神知道更好的解决方案?

想要的效果:如何同时新增数组以及字段?

await db.collection ("service_ collection").add({ data: { openid, userInfo, BlogGroup: _ . push ([colldata])}) it's a lot of trouble to write three more fields db.collection ("service_ collection").doc(openid).update({ data: { openid, userInfo, BlogGroup: _ . push ([colldata])}) this is only effective if the data exists: which God knows a better solution? Desired effect: how to add arrays and fields at the same time?

回答:

跨商通:

collection.add换成doc.set就行了。

wang li:

没看懂,你需要怎样的结构

奕K:如何同时新增数组以及字段
奕K:任意结构都可以,只是要达到这样的效果
ᯅ对方已拒绝:

我记得doc只能放生成的记录id啊 你换下试下呢

奕K:这个id指的是唯一的我这个blogid是一个变量,这个变量是唯一的,上面我说过这样写只能修改,但是不能新增字段以及数组
奕K:我想要达到同时新增字段和数组的效果

-EOF-

AI助手支持GPT4.0