Here is my collection object structure
"_id" : ObjectId("xxxxxxxxxxxxxxxxxxxxxxxx"),
"Name": "HelloWorld",
"OtherFields": "OtherValues",
"Projects" : [
{
"Project" : {
"key" : 111
},
"Category" : [
{
"No" : "123"
},
{
"No" : "987"
}
]
},
{
"Project" : {
"key" : 222
},
"Category" : [
{
"No" : "123"
},
{
"No" : "987"
}
]
}
]
I want to delete element with Category No「123」in Project with key 111
Closer thing that I did was
db.project_collection.updateOne({"_id": ObjectId("collection_obj_id")}, {"$pull": { "Projects": {"$and": [ {"Project.key": 111)}, {"Category.No": "123"} ] }} })
This command removing whole element inside "Projects"
object
But I want to delete only "Projects"
→ "Category"
→ [0]
subelement which has No 123
.
When I trying to change "Projects"
after "$pull"
to something like "Projects.Category"
or "Projects.$.Category"
The positional operator did not find the match needed from the query
error occures.
So is it possible to delete subelement without creating own backend logic?