Nedb db.remove()
db.remove(query, options, callback)
作用:
根据options配置删除所有query匹配到的文档集。
参数:
query: 与find和findOne中query参数的用法一致
options: 只有一个可用。muti(默认false),允许删除多个文档。
callback: 可选,参数: err, numRemoved
示例:
// 文档集
// { _id: 'id1', planet: 'Mars', system: 'solar', inhabited: false }
// { _id: 'id2', planet: 'Earth', system: 'solar', inhabited: true }
// { _id: 'id3', planet: 'Jupiter', system: 'solar', inhabited: false }
// { _id: 'id4', planet: 'Omicron Persia 8', system: 'futurama', inhabited: true }
// 删除一条记录
// options set to {} since the default for multi is false
db.remove({ _id: 'id2' }, {}, function (err, numRemoved) {
// numRemoved = 1
});
// 删除多条记录
db.remove({ system: 'solar' }, { multi: true }, function (err, numRemoved) {
// numRemoved = 3
// All planets from the solar system were removed
});
// 删除所有记录
db.remove({}, { multi: true }, function (err, numRemoved) {
});