复杂查询mongodb c

时间:2012-06-01 14:29:08

标签: c mongodb querying mongodb-c

我已经像这样创建了我的mongodb查询>

 86     bson query[1];
 87     bson_init(query);
 88     bson_append_start_object(query, "service.virtual_mach    ine");
 89         bson_append_oid(query,"_id",result);
 90     bson_append_finish_object(query);
 91     bson_finish(query);

我使用此>

运行它
 93     bson fields[1];
 94     bson_init(fields);
 95     bson_append_oid(fields, "_id", result);
 96     bson_finish(fields);
 97 
 98     mongo_cursor* cursor = NULL;
 99     cursor = mongo_find(conn, "db.services", query, field    s, 9999,0,0);

如果我打印“mongo_cursor_next(cursor)”方法我得到一个“-1”(错误),我想知道,我的查询中出现了什么错误。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

这一个? https://github.com/mongodb/mongo-c-driver#error-handling

  

大多数函数在成功时返回MONGO_OK或BSON_OK,在失败时返回MONGO_ERROR或BSON_ERROR。然后将特定的错误代码和错误字符串存储在mongo和bson对象的err和errstr字段中。客户有责任检查错误并妥善处理。