I have a mongo schema that looks like this:
{
"_id" : ObjectId("58e4222497b2735ba3cd9ec4"),
"place" : "",
"plant" : "Test1",
"eventDate" : ISODate("2017-04-05T00:00:00Z"),
"event" : "Test123",
"toBeTested" : [
{
"_id" : ObjectId("58e453a07c9f94702ebac93d"),
"thingsTested" : [
"A1",
"A2",
"A3"
]
}
]}
I'm using mongoose to remove a single element of thingsTested. My code in mongoose is:
Layout
.update(
{_id: req.params.parentid},
{$pull: {toBeTested: {thingsTested: 'A3'}}},
function (err, docs){
if (err) {
res.send(err);
}
res.json(docs);
}
);
As you can see, I've hardcoded that I want to remove A3 from the thingsTested set. However, the exhibited behavior is that all of thingsTested is being deleted.
As a followup question, how can I make sure that the mongoose command only removes A3 in thingsTested with the _id of 58e453a07c9f94702ebac93d (the child ID)?
Thanks!
via black_sheep07
No comments:
Post a Comment