how to unwind in map/reduce

1,103 views
Skip to first unread message

Vishnu Viswanath

unread,
Jan 25, 2014, 2:44:56 PM1/25/14
to mongod...@googlegroups.com
Hi

I have a doc with array of elements,
I would like to do map/reduce after unwinding the doc. how can i do this?

Thanks

Stephen Steneker

unread,
Jan 25, 2014, 4:33:32 PM1/25/14
to mongod...@googlegroups.com
On Sunday, 26 January 2014 06:44:56 UTC+11, Vishnu Viswanath wrote:
I have a doc with array of elements,
I would like to do map/reduce after unwinding the doc. how can i do this?

Hi Vishnu,

If you want to unwind arrays in Map/Reduce, you can iterate the array(s) in your map() function and emit multiple values for the same document.

Here is an example in the MongoDB manual using a "for" loop:

Depending on the aggregation result you are trying to achieve, you may find it easier and more performant to write your query in the Aggregation Framework rather than Map/Reduce:

Regards,
Stephen

Reply all
Reply to author
Forward
0 new messages