Hi, I am having some issues dealing with a removal of all embedded objects with a specific trackId from an embedded Object. Here is my data:
{“_id”:{“$oid”:“61ec382b9a3a0a0bd76637f0”},“email":"andres@hop.com”,“password”:“$2b$10$Uy6yfdfdNv40TaDO21/wFXO7Nus2lYmImsdffdrvuSztwEcIIy5A/lHV7QnnWK”,“notifications”:,“__v”:{“$numberInt”:“0”},“name”:“Andres”,“collections”:[{“name”:“NEw”,“_id”:{“$oid”:“61ed6eda894f201120f7fa24”},“tracks”:[{“trackId”:{“$oid”:“61ed6f1703f45ccd03aeeb5f”},“_id”:{“$oid”:“61ed6f1b03f45ccd03aeeb66”}}]}]}
The information I am trying is to remove is any tracks objects with a specific trackId. Here is the code I think should work, but for some reason its not giving me an modified counts back:
const response = await Account.updateOne(
{ _id: userId },
{ $pull: { collections: { tracks: { trackId: trackId } } } }
);
I am able to remove the item if I move the $pull location into collections like this:
const response = await Account.updateOne(
{ _id: userId },
{ collections: { $pull: { tracks: { trackId: trackId } } } }
);
However this then strips the name out of the collection section. I think I must be missing something, but I’m a little lost for what to try next!