3

我想在 C 驱动程序中对 mongoDB 执行 mapreduce。

但是,只有一种方法可以成功实现目标。

那是,

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

因为 $eval 可能会阻塞读写过程,直到它完成。

我听说“mongo_run_command”也可以做到这一点。

无论我尝试了多么简单的示例,我都无法使 mapreduce 在 mongo C 驱动程序上工作。

此外, conn->lasterrstr 和 conn->errstr 什么都没有了。

这是代码:

    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

----数据库----

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})

----数据库----

有人可以让它工作或给我另一种方式来实现mapreduce吗?

谢谢。

4

0 回答 0