uni-app云开发批量删除

708 阅读1分钟
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const collection = db.collection('unicloud-test')
	const dbCmd = db.command
	const docList = await collection.limit(1).get()
	//console.log(event, docList);
	if (!docList.data || docList.data.length === 0) {
		return {
			status: -1,
			msg: '集合unicloud-test内没有数据'
		}
	}
	let list = event.list 
	let res = await collection.where({ 
        _id:dbCmd.in(list)
	}).remove()
	return res
};

通过查询筛选指令 in,批量删除数据