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.