I thought it would be particularly helpful if you could map keys (aka field names) to be field values and vice versa. This feature did not exist (and still doesn't) so I filed a request for it in MongoDB issue tracking system.
Meanwhile, as I show here it is still possible to do this "projection" via aggregation if you know the names of the fields in advance.
But what if you get the names of fields dynamically, rather than always knowing they will be field1, field2?
My sample documents and schema will be like this:
Now imagine I want to output documents which have this shape:
- no duplicate attribute names for a particular document
- all attribute values would be alphanumeric and compare greater than "space" character (ASCII x20)
I hope this is helpful, if not for actual implementation, at least for thinking about how you want to structure your documents. In the future I will take a closer look at advantages and disadvantages of different ways of storing attributes in your schema design.