3

I would like to perform mapreduce on mongoDB in C driver.

However, there is only one way I can successfully achieve the goal.

that is,

    mongo_simple_str_command( conn, "db", "$eval",legalCommand, &b )

Since $eval may block reading and writing process until it finished.

I have heard "mongo_run_command" can also do this.

No matter how simple example I tried, I can't make mapreduce work on mongo C driver.

Moreover, conn->lasterrstr and conn->errstr are nothing left.

Here is the code:

    bson_init( &cmd );

    bson_append_string( &cmd, "mapreduce", "country2" );

    bson_append_string( &cmd, "map"   , "function()      {emit(this.city, this.pop);}" );

    bson_append_string( &cmd, "reduce", "function(keyCustId, value) {return value;  }" );

    bson_append_string( &cmd, "out", "c" );

    bson_finish( &cmd );

    mongo_run_command( conn, "country2", &cmd, &output );//the return value is always -1

----databsed----

db.country2.insert({city:'tai',pop:100,land:3})

db.country2.insert({city:'pei',pop:120,land:4})

db.country2.insert({city:'kao',pop:10,land:30})

----databsed----

Does someone can make it work or give me another way to achieve mapreduce?

Thanks.

Ray
  • 568
  • 6
  • 20
  • your reduce function doesn't actually do any reducing - what exactly are you trying to do with map/reduce? – Asya Kamsky Mar 21 '13 at 06:08
  • My purpose is just to generating a collection 'c' via mapReduce function. Acturelly, I had tried a lot of method. This is the simplest action that ensuring whether mapReduce works or not. – Ray Mar 21 '13 at 09:39
  • my question was more to find out if what you need to do needs mapreduce or if maybe it can be done with aggregation framework. – Asya Kamsky Mar 21 '13 at 17:05
  • In fact, I am writing a mongoDB shell and trying to achieve all the function working. Therefoe I just try to make all function work in order to future using. – Ray Mar 22 '13 at 01:49

0 Answers0