Query.prototype.deleteMany()
Parameters
[filter] «Object|Query» mongodb selector
[options] «Object» optional see
Query.prototype.setOptions()
[callback] «Function» optional params are (error, mongooseDeleteResult)
Returns:
- «Query» this
Declare and/or execute this query as a deleteMany()
operation. Works like remove, except it deletes every document that matches filter
in the collection, regardless of the value of single
.
This function triggers deleteMany
middleware.
Example
await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
// Using callbacks:
Character.deleteMany({ name: /Stark/, age: { $gte: 18 } }, callback);
This function calls the MongoDB driver’s Collection#deleteMany()
function. The returned promise resolves to an object that contains 3 properties:
ok
:1
if no errors occurreddeletedCount
: the number of documents deletedn
: the number of documents deleted. Equal todeletedCount
.
Example
const res = await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
// `0` if no docs matched the filter, number of docs deleted otherwise
res.deletedCount;
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .