I am trying to remove an object form an array based on the name(Ticker) of an object. Others have also asked this question and I have tried many of their solutions but I just cant get it to work. It never actually performs the task of removing anything.
Here is my schema:
{
_id : 1234
email : [email protected]
pass : password
stock : [
{
Ticker : TSLA
Market : Nasdaq
Notes : [
"Buy at 700",
"Sell at 1000"
]
},
{
Ticker : AAPL
Market : Nasdaq
Notes : [
"Buy at 110",
"Sell at 140"
]
},
]
}
Here is what I currently have, but I've also tried a few other combinations of commands:
router.post(`/watchlist/remove/:email/:pass/:stock`, (req, res) => {
var email = req.params.email
var pass = req.params.pass
var tempStock = req.params.stock
userModel.findOneAndUpdate({ email: email }, { $pull : {'stock.Ticker' : tempStock} } , (documents, err) => {
if (err) {
res.send(err);
}
else {
res.send(documents)
}
})
})