I have an array like this:
{
"_id" : ObjectId("5ae5afc93e1d0d2965a4f2d7"),
"entries" : [
{
"_id" : ObjectId("5b159ebb0ed51064925dff24"),
"tags" : [
ObjectId("5b142608e419614016b89925"),
ObjectId("5b142b40e419614016b89937")
]
}
],
"tags" : [
{
"_id" : ObjectId("5b142608e419614016b89925"),
"name" : "Outdated",
"color" : "#3498db"
},
{
"_id" : ObjectId("5b142b40e419614016b89937"),
"name" : "Todo",
"color" : "#e8b00a"
}
],
}
I would like to remove "tagId2" from every item in entries
. I'm trying to use the position operator for this which is supposed to work with arrays:
db.projects.updateOne(
{
"_id" : ObjectId("5ae5afc93e1d0d2965a4f2d7"),
},
{
$pull: {
'entries.$[].tags': ObjectId("5b142b40e419614016b89937")
}
})
But I get a MongoDB error:
WriteError: cannot use the part (entries of entries.$[].tags) to traverse the element ([the entries array])
How do I use it correctly? Thanks.