刪除多個檔案
刪除告別屬性設定為正常的所有文件。
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/test';
MongoClient.connect(url, function (err, db) {
if (err) throw new Error(err);
db.collection('myCollection').deleteMany(// MongoDB delete method 'deleteMany'
{ farewell: "okay" }, // Delete ALL documents with the property 'farewell: okay'
function (err, result) {
if (err) throw new Error(err);
db.close(); // Don't forget to close the connection when you are done
});
});
收集方法 deleteMany()
db.collection( collection ).deleteMany( filter , options , callback )
引數 | 型別 | 描述 |
---|---|---|
filter |
文獻 | 指定選擇標準的文件 |
options |
賓語 | (可選) 可選設定 (預設值:null) |
callback |
功能 | 操作完成時要呼叫的函式 |
callback
函式有兩個引數
err
:錯誤 - 如果發生錯誤,將定義 err 引數db
:object - MongoDB 例項