Query.prototype.deleteOne()
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 deleteOne()
operation. Works like remove, except it deletes at most one document regardless of the single
option.
This function triggers deleteOne
middleware.
Example
await Character.deleteOne({ name: 'Eddard Stark' });
// Using callbacks:
Character.deleteOne({ name: 'Eddard Stark' }, callback);
This function calls the MongoDB driver’s Collection#deleteOne()
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.deleteOne({ name: 'Eddard Stark' });
// `1` if MongoDB deleted a doc, `0` if no docs matched the filter `{ name: ... }`
res.deletedCount;
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .