Mapreduce possabilities?

2 views
Skip to first unread message

PenFold

unread,
Jul 24, 2010, 9:15:13 AM7/24/10
to mongodb-user
I understand the standard way to use mapreduce, but is the following
idea allowed/possible?

Use the map function to apply some custom logic that only emits for
certain documents/objects? This would allow aggregation and complex
filtering to be possible. [I'm thinking about scaling to a sharded
system in the long run.]

My assumption is that this may be possible, if the the map emit is
simply added to temp collection. Therefore, if no emit was called for
a document/object then it is not added to this temp collection and not
feed to the reduce.

Your thoughts?

Thanks,
PenFold

Eliot Horowitz

unread,
Jul 24, 2010, 9:50:02 AM7/24/10
to mongod...@googlegroups.com
There are 2 ways to do this:
- specify a query on the map/reduce. So you can apply a regular
mongo query and only matching documents get passed to map
- in your map - conditionally emit based on any criteria

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

PenFold

unread,
Jul 24, 2010, 10:02:04 AM7/24/10
to mongodb-user
Thanks for your quick reply.

The docs say that I should have atleast one emit in the map function.
I'm assuming from your reply and some testing that it doesn't have to
be called atleast once per object. Is this correct?

It does seem to work very well.

I'm going with the conditional emit on the map in addition to a query.
It is just easier to encode part of the logic in JS (and it also
allows me to include a significant optimisation.).

Thanks,
PenFold.

Eliot Horowitz

unread,
Jul 24, 2010, 6:42:12 PM7/24/10
to mongod...@googlegroups.com
The docs might be a bit basic.
You can have anywhere between 0 and n emits per map.
Typically you have 1, but its designed to be very flexible.
Reply all
Reply to author
Forward
0 new messages