简体   繁体   中英

Formatting MongoDB MapReduce output

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM