c 语言驱动访问mongodb 如何写bson

zlxi 2016-11-13 03:53:49
   
BOOL RSmppMongoDb::_db_res_query()
{
const bson_t *doc;
bson_error_t error;

const char *collection_name = "cac_sms_sent_pool";
bson_t *query;
char *str;
mongoc_collection_t *collection;
mongoc_cursor_t *cursor;


query = bson_new ();
BSON_APPEND_UTF8 (query, "apply_state", "0");
collection = mongoc_client_get_collection (m_pClient, "cac", collection_name);
cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, \
query, NULL,/* Fields, NULL for all. */ NULL); /* Read Prefs, NULL for default */
while (mongoc_cursor_next (cursor, &doc))
{
str = bson_as_json (doc, NULL);
fprintf (stdout, "%s\n", str);
bson_free (str);
}

if (mongoc_cursor_error (cursor, &error)) {
fprintf (stderr, "Cursor Failure: %s\n", error.message);
return EXIT_FAILURE;
}

bson_destroy (query);
mongoc_cursor_destroy (cursor);
mongoc_collection_destroy (collection);
}

英语水平不好,需要的太急了,就来论坛上问问。

1.如何保证则连接是正常的。教程中没有看到判断。
2.如果要查出来前面20000条,如何写。
3.如何更新某个字段,(像mysql SET return_message_id =concat(IFNULL(return_message_id,''),'%s ')) 一样。
--先判断某个值,如果是这个值就不更新。如果不是这个值就更新成另外一个值。
...全文
202 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlxi 2016-11-13
  • 打赏
  • 举报
回复
自己定上去吧

1,747

社区成员

发帖
与我相关
我的任务
社区描述
MongoDB相关内容讨论区
社区管理员
  • MongoDB社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧