Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Mongoid have Map/Reduce?

I am using Ruby code to calculate sum from the array returned by Mongoid.

But maybe using Map/Reduce can be faster, except I don't see any docs for Map Reduce on mongoid.org and Google for

map reduce site:mongoid.org

doesn't give any result either. (or using MapReduce or Map/Reduce)

There are docs on MongoDB's site

map reduce site:mongodb.org

but need to use Map Reduce with Mongoid as well.

like image 556
nonopolarity Avatar asked Sep 15 '10 23:09

nonopolarity


People also ask

What is MongoDB mapReduce?

In MongoDB, map-reduce is a data processing programming model that helps to perform operations on large data sets and produce aggregated results. MongoDB provides the mapReduce() function to perform the map-reduce operations. This function has two main functions, i.e., map function and reduce function.

What is emit in MongoDB?

The map function may optionally call emit(key,value) any number of times to create an output document associating key with value . In MongoDB 4.2 and earlier, a single emit can only hold half of MongoDB's maximum BSON document size. MongoDB removes this restriction starting in version 4.4.

What is difference between mapReduce and aggregation?

Map-reduce is a common pattern when working with Big Data – it's a way to extract info from a huge dataset. But now, starting with version 2.2, MongoDB includes a new feature called Aggregation framework. Functionality-wise, Aggregation is equivalent to map-reduce but, on paper, it promises to be much faster.


1 Answers

You can use map reduce with Mongoid just as you could through the Ruby driver directly:

# Post is a Mongoid model...
Post.collection.map_reduce(map_function, reduce_function, options)

For some examples of doing map reduce in the Ruby driver, see this blog post by Kyle Banker (maintainer of the Ruby MongoDB driver).

like image 77
PreciousBodilyFluids Avatar answered Sep 23 '22 03:09

PreciousBodilyFluids