Collection.update
2020-08-28 15:20 更新
更新集合内符合查询条件的文档
返回值 Promise
resolve 结果:
| 名称 | 类型 | 说明 |
|---|---|---|
| updated | Number | 更新文档数量 |
reject 结果:
| 名称 | 类型 | 说明 |
|---|---|---|
| code | String | 错误码 |
| message | String | 错误信息 |
代码示例
const cloud = require('swan-server-sdk')
exports.main = async (event, context) => {
cloud.init(context)
const db = cloud.database()
const cmd = db.command
try {
return await db.collection('articles').where({
status: 0
}).update({
visits: cmd.inc(1)
})
}
catch(err) {
console.log(err)
}
}
以上内容是否对您有帮助:

免费 AI IDE


更多建议: