how to use map-reduce ?

703 views
Skip to first unread message

tasyjean sozoran

unread,
Jul 13, 2013, 10:44:38 PM7/13/13
to reacti...@googlegroups.com
Hi

is map-reduce supported in version .9 ? if so how to use it ?


Thanks!

Cheers,
Tasyjean

Mark van der Tol

unread,
Jul 15, 2013, 9:40:11 AM7/15/13
to reacti...@googlegroups.com
Hi,

There is no build-in command for MapReduce, but you can make use of the RawCommand to send commands which have no convenience method in ReactiveMongo.

The code for doing a map-reduce would look something like this:

val db: DefaultDB = …
val mapReduceCommand = BSONDocument(
  "mapreduce" -> "inputCollectionName",
  "map" -> BSONString(map),
  "reduce" -> BSONString(reduce),
  "out" -> BSONDocument("replace" -> "outputCollectionName")
)
val result = db.command(RawCommand(mapReduceCommand))

All possible parameters for the mapReduce command are specified here: http://docs.mongodb.org/manual/reference/command/mapReduce/

Mark

tasyjean sozoran

unread,
Jul 17, 2013, 9:03:45 AM7/17/13
to reacti...@googlegroups.com
Great ! 
thank you



Tasyjean

Loïc Descotte

unread,
Dec 20, 2014, 9:05:32 AM12/20/14
to reacti...@googlegroups.com
Hi, 

In the MongoDB documentation examples, map and reduce are javascript functions, for example with loops, so I'm no sure ton understand how to fill this in a BSONDocument object.
Do you have an example of mapreduce using ReactiveMongo?

Thanks
Loïc

Le mercredi 17 juillet 2013 15:03:45 UTC+2, tasyjean sozoran a écrit :
Great ! 
thank you



Tasyjean

Loïc Descotte

unread,
Dec 23, 2014, 2:18:22 AM12/23/14
to reacti...@googlegroups.com
I just found an example on the lichess game code (may be helpful to other people having the same question).  You just need to write a JS function String : 
Reply all
Reply to author
Forward
0 new messages