delete subdocument mongoose code example
Example 1: mongoose nested object without id
var subSchema = mongoose.Schema({
},{ _id : false });
Example 2: how to delete subdocument mongodb
db.getCollection('products').update({},
{$pull: {reviews:
{user: ObjectId("5f6e2e0b70eb0208fc84011a")}}},
{multi: true})
Example 3: how to delete popultate subdocument mongoose
Surf
.find({user_id: {$in: userIds}})
.populate('user_id', 'name boards')
.populate('friends', 'name')
.exec(function (err, surfs) {
if (err) {
return handleError(res, err);
}
surfs.forEach(function (surf) {
surf.set('boardInfo', surf.user_id.boards.id(surf.board_id), {strict: false});
});
return res.json(200, surfs);
});