In all of the MongoDB MapReduce examples that I can find, output is formatted like this:
{ "_id" : ..., "value" : { "v1" : ..., "v2" : ..., "vn" : ... } }
I would like to know if it is possible to write a MapReduce command to instead format output like this:
{ "_id" : ..., "v1" : ..., "v2" : ..., "vn" : ... }
If so, what is the best way to accomplish this?
This is not possible due to the way MR actually writes out.
It writes out to a value field, the same rules apply as they did of this question here: In MongoDB mapreduce, how can I flatten the values object?. To save you from having to click on two links here is the JIRA for your functionality: https://jira.mongodb.org/browse/SERVER-2517
Of course you could always run some post-processing function after the MR to change the way the collection looks but this is normally unperformant and slow method to do something you could easily handle in your queries.