I have a model that looks like this:
contacts: {
phones: [{
phone_id: {
type: ObjectId
},
phone_number: {
type: String
}
}],
shared: {
phones: [{
phone_id: {
type: ObjectId
},
phone_number: {
type: String
},
}]
}
}
I have an endpoint, where I am trying to delete phone numbers matching an id I pass in my query string.
My code looks like this:
Contacts.update({ 'phones._id': req.params.phone_id },
{ "$pull": { "phones": { "_id": req.params.phone_id} }},
{ safe: true, multi:true }, function(err, obj) {
});
Contacts.update({ 'shared.phones._id': req.params.phone_id },
{ "$pull": { "shared.phones": { "_id": req.params.phone_id} }},
{ safe: true, multi:true }, function(err, obj) {
});
The first update that removes the number form the phones array works.
But the second that should remove the number from the 'shared.phones' array does not.
Any idea on what I'm missing?
I tried using the '$' positioning operator like this:
Contacts.update({ 'shared.phones.$._id': req.params.phone_id },
{ "$pull": { "shared.phones.$": { "_id": req.params.phone_id} }},
{ safe: true, multi:true }, function(err, obj) {
});
But that didn't work as well.
Thanks in advance!
{ $pull: { 'shared.phones._id': req.params.phone_id } }