I have the following document structure:
And am trying to figure out how to delete a single object from the 'saved array', using the id in the object to select it (eg id 4182 will delete the object and all its properties at index 0). This was my attempt but not sure how to target it properly (No errors, but nothing updated):
let id = req.query.clicked_id;
console.log("\deleteSaved id:", id);
db.collection("users").updateOne(
{ username: config.username },
{ $unset: { id: id} },
(err, data) => {
if (err) {
console.log(err);
}
console.log("Item deleted from DB: ", id, data.result.nModified);
res.redirect("/saved");
}) ;
Thanks