In my collection, all of my documents have an array called tags:
"tags" : [
{
"name" : "a",
"weight" : NumberInt(32)
},
{
"name" : "b",
"weight" : NumberInt(26)
},
{
"name" : "c",
"weight" : NumberInt(25)
},
...
]
Each object in the array has keys name and weight. I need to remove the weight key, so that I'm just left with the names in an single-level array like ["a", "b", "c"...]
An explanation of why I need to do this:
Inside my aggregation, I want to calculate the number of matches between an array x = ["a", "b", "d"] and whatever tags each document has.
This is as far as I've gotten- inside a $project I create a new variable like so:
"$project": {
...
"diff": {
"$size": {
"$setIntersection": [ x, "$tags" } ]
}
},
...
}
But of course this doesn't work as the $tags array is full of objects, and not strings. I need to strip the weight from the tags array and leave it just as an array of names like ["a", "b", "c" ...], then it should work.
How would I go about doing this?