使用 C & 计算 Mongo 游标中的文档数BSON。
我正在开发一个项目,需要使用 BSON 和 C 来计算游标中的文档数量(MongoDB)。
这是我的代码:
bson_buffer_init(query_buf);
bson_append_string(query_buf, "url", bson_iterator_string(it));
bson_from_buffer(query, query_buf);
similar = mongo_find(conn, "testing.test", query, NULL, 0, 0, 0);
while(mongo_cursor_next(similar))
{
bson_iterator it2[1];
if(bson_find(it2, &similar->current, "url"))
{
printf("%s\n", bson_iterator_string(it2));
}
}
How will I alter this in order to count the Documents in every Cursor(上面的内容在一个循环,每次传递的 url 都不同)?
I'm working on a project and need to count the amount of documents (MongoDB) in a cursor with BSON and C.
Here is my code:
bson_buffer_init(query_buf);
bson_append_string(query_buf, "url", bson_iterator_string(it));
bson_from_buffer(query, query_buf);
similar = mongo_find(conn, "testing.test", query, NULL, 0, 0, 0);
while(mongo_cursor_next(similar))
{
bson_iterator it2[1];
if(bson_find(it2, &similar->current, "url"))
{
printf("%s\n", bson_iterator_string(it2));
}
}
How would I alter this in order to count the documents in each cursor (the above is in a loop, url is different each pass)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过
mongo_count
方法吗?根据消息来源,它就在这里:
https://github.com/mongodb/mongo -c-driver/blob/master/src/mongo.c#L385
请注意,C 驱动程序仍被视为 Alpha 质量。如果您发现任何错误,请告知 MongoDB 团队:http://jira.mongodb.org/
Have you tried the
mongo_count
method?According to the source, it's right about here:
https://github.com/mongodb/mongo-c-driver/blob/master/src/mongo.c#L385
Note that the C drivers are still considered Alpha quality. If you find any bugs, please let the MongoDB team know: http://jira.mongodb.org/