0
Hey, ich habe ein Problem mit verschachtelten Array aus meiner Datenbank zu entfernen, möchte ich findOneAndUpdate
und $pull
verwenden. Mein Punkt ist, Artikel aus reply
Array zu entfernen. Ich versuche, Kommentare von _id
finden und entfernen Sie diese Antwort, aber das funktioniert nicht. Bitte schau auf meinen Code unten.
mein Schema
var productSchema = new Schema({
description: [{
type: String,
require: true,
}],
comments: [{
body: {
type: String,
trim: true,
},
author: {
type: String,
},
date: {
type: Date,
},
reply: [{
body: {
type: String,
trim: true,
},
author: {
type: String,
}, date: {
type: Date,
}
}]
}]
});
api
router.put('/dashboard/admin/komentarz/odpowiedz/usun/', function(req, res) {
var currentCourse = req.body._id; // main item id
var deleteReply = req.body.reply; // reply item id
var commentId = req.body.commentId // comments item id
Product.findOneAndUpdate({ _id: currentCourse }, { $pull: { reply: req.body.reply }}, function(err, product){
//some code
})