猫鼬:在 Model.remove() 中设置单个选项
Mongoose: set single option in Model.remove()
Documentation 说到 Model::remove()
方法:
Removes all documents that match conditions from the collection. To
remove just the first document that matches conditions, set the single
option to true.
问题是如何设置这个选项?
我试过:
1) Model.remove({code: 55, single: true }, function (err, deleted) {...
— 没有结果,因为正如我所料,在这种情况下 single
被视为一个不存在的字段;
2) Model.remove({code: 55}, {single: true }, function (err, deleted) {
— TypeError: callback.apply is not a function
.
我是 Mongoose 初学者,在此先感谢您的帮助。
哦,天哪,我找到了,如何解决它 - in source code:
Model.remove({code: 55}).setOptions({ single: true }).exec(function (err, deleted) {...
Documentation 说到 Model::remove()
方法:
Removes all documents that match conditions from the collection. To remove just the first document that matches conditions, set the single option to true.
问题是如何设置这个选项?
我试过:
1) Model.remove({code: 55, single: true }, function (err, deleted) {...
— 没有结果,因为正如我所料,在这种情况下 single
被视为一个不存在的字段;
2) Model.remove({code: 55}, {single: true }, function (err, deleted) {
— TypeError: callback.apply is not a function
.
我是 Mongoose 初学者,在此先感谢您的帮助。
哦,天哪,我找到了,如何解决它 - in source code:
Model.remove({code: 55}).setOptions({ single: true }).exec(function (err, deleted) {...