I have mongoose schemas like this:
var question = new Schema({
title : String,
gambar : String
});
var polling = new Schema({
id_poll : String,
soal : [question]
});
i want to remove all subdocs soal by its index of array, using findOneAndRemove method like this,
polling.findOneAndRemove({_id:req.params.poll_id, soal[req.params.soal]._id: req.params.id_soal}, function(err){
if(err) throw err;
console.log("soal deleted");
});
but it throws error like this:
polling.findOneAndRemove({_id:req.params.poll_id, soal[req.params.soal]._id:
^
SyntaxError: Unexpected token [
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3
so how can i remove the subdocs without knowing its index, i have google it and find using operator $pull
but i still don't understand how to apply it to my code. need advice and help. thank you so much