删除多条数据 
使用 db.collection(<collection_name>) 对象中的 deleteMany 方法,您可以删除 T1 后端云应用 NoSQL 数据库中的多条数据。
通过 ID 进行删除 
js
function main() {
    let filter = { _id: { $in: [db.toObjectID('abc'), db.toObjectID('123')] } }
    let deletedCount = db.collection('users').deleteMany(filter) // 删除 users 集合中 ID 为 abc 和 123 的数据
    if (deletedCount == 0) {
        return '没有数据被删除'
    }
    return '成功删除' + deletedCount + '条数据'
}通过其它字段进行删除 
js
function main() {
    let filter = { name: '王华', age: 21 }
    let deletedCount = db.collection('users').deleteMany(filter) // 删除 users 集合中 name 为 王华 并且 age 为 21 的全部数据
    if (deletedCount == 0) {
        return '没有数据被删除'
    }
    return '成功删除' + deletedCount + '条数据'
}通过操作符条件删除 
条件操作符
| 操作符 | 说明 | 
|---|---|
$eq | 等于 | 
$ne | 不等于 | 
$gt | 大于 | 
$lt | 小于 | 
$gte | 大于等于 | 
$lte | 小于等于 | 
$in | 在给定的数组中 | 
$nin | 不在给定的数组中 | 
$and | 逻辑与 | 
$or | 逻辑或 | 
$not | 逻辑非 | 
$nor | 不匹配任何条件 | 
$exists | 判断字段是否存在 | 
$regex | 匹配正则表达式 | 
$all | 匹配数组中包含所有指定元素的数据 | 
$elemMatch | 匹配数组中至少一个元素满足所有指定条件的数据 | 
$size | 匹配数组大小 | 
$bitsAllSet | 所有指定位都设置为 1 | 
$bitsAnySet | 指定位之一设置为 1 | 
$bitsAllClear | 所有指定位都清除为 0 | 
$bitsAnyClear | 指定位之一清除为 0 | 
$text | 执行全文本搜索 | 
$year, $month, $dayOfMonth, $hour, $minute, $second, $millisecond | 日期操作符,用于提取日期字段的各个部分。 | 
js
function main() {
    let filter = { age: { $lt: 18 } }
    let deletedCount = db.collection('users').deleteMany(filter) // 删除 users 集合中 age 小于 18 的全部数据
    if (deletedCount == 0) {
        return '没有数据被删除'
    }
    return '成功删除' + deletedCount + '条数据'
}删除全部数据 
js
function main() {
    let filter = {}
    let deletedCount = db.collection('users').deleteMany(filter) // 删除 users 集合中的全部数据
    if (deletedCount == 0) {
        return '没有数据被删除'
    }
    return '成功删除' + deletedCount + '条数据'
}