1. 使用 remove 删除数据
'use strict';
const db = uniCloud.database()
// 挂载 command 指令
const dbCmd = db.command
exports.main = async (event, context) => {
const collection = db.collection('users');
let res = await collection.doc("63e1b1d309e2987cee43ca8a").remove()
return res
};
2. 数据删除保护机制
最好使用 where 在删除时候对需要删除的数据进行一下过滤保护,避免一下子全部删掉了
let res = await collection.where({
_id:dbCmd.neq(-1)
}).remove()