数据库中有商品表{name:'菠菜',数量:1},{name:'萝卜’,数量:2},{name:'土豆',数量:3},现在客户端传递一个数组{name:'菠菜',数量:3},{name:'萝卜’,数量:4},怎么写可以一次性把这两条记录都更新了呢?
云数据库更新多个记录?Cloud database update multiple records?
云数据库更新多个记录?数据库中有商品表{name:'菠菜',数量:1},{name:'萝卜’,数量:2},{name:'土豆',数量:3},现在客户端传递一个数组{name:'菠菜',数量:3},{name:'萝卜’,数量:4},怎么写可以一次性把这两条记录都更新了呢?
There is a commodity table {Name: 'spinach', quantity: 1}, {Name: 'radish', quantity: 2}, {Name: 'potato', quantity: 3} in the database. Now the client passes an array {Name: 'spinach', quantity: 3}, {name: 'radish', quantity: 4}. How can I update these two records at one time?
回答:
首先你这个存的是一个数组,那就一定有角标,也就是说角标你是否知道?
db.collection('你的集合').doc('t996_007').update({
data: {
商品表[0].数量: '你需要改的值',
商品表[1].数量: '你需要改的值'
}
}).then(res => {
console.log(res)
})
如果不知道的话,就得where查询了,一次搞不定的
1、只能多次update
原文出处:云数据库更新多个记录?
只能一个一个更新,多次用update,最好用异步的同步来操作,即await async