云函数如何批量修改前4条数据?
发布于 6 年前 作者 yfang 13801 次浏览 来自 官方Issues

const db = cloud.database()

// 云函数入口函数

exports.main = async (event, context) => {

try {

return await db.collection('PLgame').where({

GZT: 0,//空闲中

}).limit(4).update({

data: { GZT: 1 },

})

} catch (e) {

console.error(e)

};


}

我只想修改符合条件的前4条数据,使用limit(4)限制没起作用,代码该怎么写

1 回复

限制不了的

先取出前四条数据_id,组成一个数组ids

where({

    _id: _.in(ids)

}).update({…})

回到顶部