0
我有架構貓鼬
var postSchema = new Schema({
comments: [{
nickName: {type: String, required: true},
comment: {type: String, required: true}
}]
});
然後我想拉的意見
Post.findOneAndUpdate({'_id': req.body._id}, {$pull: {'comments': {'_id': req.body._idComment} }},
function(err, data) {
if (err) {
res.send({status:400});
} else {
// how get $pull object if I don't know index of element of array
// data returns all objects
}
});