There is a structure:
{ "A" : { "B1" : { "C" : { "K1" : { "x" : NumberLong(12), "y" : NumberLong(13) } } }, "B2" : { "C" : { "K1" : { "x" : NumberLong(35), "y" : NumberLong(45) }, "K2" : { "x" : NumberLong(1), "y" : NumberLong(0) } } } } } There is a task: Select all K1 (the variable that is passed) from all B n
I tried it myself but there are problems:
- How to specify not explicitly B1 , but all B n
- As in the result of category to push the very name of the key B n
.aggregate([ {$match:{ "A.B1.C.K1":{ $exists:true } }}, {$project:{ "result":"A.B1.C.K1", "category":"B1", "_id":false }} ]);