Query.prototype.remove()
Parameters
[filter] «Object|Query» mongodb selector
[callback] «Function» optional params are (error, mongooseDeleteResult)
Returns:
- «Query» this
Declare and/or execute this query as a remove() operation. remove()
is deprecated, you should use deleteOne()
or deleteMany()
instead.
This function does not trigger any middleware
Example
Character.remove({ name: /Stark/ }, callback);
This function calls the MongoDB driver’s Collection#remove()
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.remove({ name: /Stark/ });
// Number of docs deleted
res.deletedCount;
Note
Calling remove()
creates a Mongoose query, and a query does not execute until you either pass a callback, call Query#then()
, or call Query#exec()
.
// not executed
const query = Character.remove({ name: /Stark/ });
// executed
Character.remove({ name: /Stark/ }, callback);
Character.remove({ name: /Stark/ }).remove(callback);
// executed without a callback
Character.exec();
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .