Can somebody tell me please if is possible to use field value as key in mongodb result. If I have documentes like
{\'code\': \'xxx\', \'item\': \'yyy\'} {\'
You have to use $arrayToObject if you want to build your keys dynamically. It takes an array of k and v fields as a parameter. To make it root you can use $replaceRoot stage, try:
k
v
db.col.aggregate([ { $replaceRoot: { newRoot: { $arrayToObject: [ [ { k: "$code", v: "$item" } ] ]} } } ])