基本使用
deleteOne
- 單筆刪除(只回傳筆數)
const collection: Collection<User> = db.collection<User>("user");
const query = {
name: 'Fred'
}
await collection.deleteOne(query);
findOneAndDelete
- 查詢而刪除(會回傳查的資料)
const collection: Collection<User> = db.collection<User>("user");
const query = {
name: 'Fred'
}
await collection.findOneAndDelete(query);
deleteMany
- 多筆刪除(只回傳筆數)
const collection: Collection<User> = db.collection<User>("user");
const query = {
name: /F/ // 正則過濾
}
await collection.deleteMany(query);