Limit is ignored when remove (mongoose)
MongoDB's remove operation doesn't support a limit option, but you can find
the _id
s of the docs you want to remove, and then use $in
to remove them:
Model.find({u: "abc"}).select('_id').sort({_id: 1}).limit(10)
.exec((err, docs)=> {
const ids = docs.map((doc)=> doc._id);
Model.deleteMany({_id: {$in: ids}}, (err)=> {...});
}
);