• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 79  文章 - 58  trackbacks - 0
            <2015年3月>
            22232425262728
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(9)

            隨筆分類(lèi)

            隨筆檔案

            文章檔案

            相冊(cè)

            搜索

            •  

            積分與排名

            • 積分 - 295356
            • 排名 - 87

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            1、查詢(xún)樣例

            bson_t query;
            bson_t child;
            bson_init(&query);

            BSON_APPEND_INT64(&query, "id", 0);

            mongoc_cursor_t m_pCursor = mongoc_collection_find(m_pCollection,
                MONGOC_QUERY_NONE,
                0,
                0,
                0,
                &query,
                NULL,  /* Fields, NULL for all. */
                NULL); /* Read Prefs, NULL for default */

            bson_destroy(&query);
            bson_error_t error;
            if (mongoc_cursor_error(m_pCursor, &error)) {
                cout << "Query Failure: " << error.message;
                return;
            }

            const bson_t *doc;

            while (!mongoc_cursor_error(m_pCursor, &error)
                && mongoc_cursor_more(m_pCursor))
            {
                if (mongoc_cursor_next(m_pCursor, &doc))
                {
                    GetRecord(doc);
                }
                else
                {
                    break;
                }
            }
            if (mongoc_cursor_error(m_pCursor, &error)) {
                cout << "Query Failure: " << error.message;
            }

            mongoc_cursor_destroy(m_pCursor);

            2、獲取記錄

            void GetRecord(const bson_t *doc)
            {
                bson_iter_t iter;
                bson_iter_init(&iter, doc);

                if (bson_iter_find(&iter, "id"))
                {
                    cout << bson_iter_int64(&iter) << "|";
                }
               
                if (bson_iter_find(&iter, "field1"))
                {
                    cout << bson_iter_int64(&iter) << "|";
                }

                if (bson_iter_find(&iter, "field2"))
                {
                    const uint8_t *binary = NULL;
                    bson_subtype_t subtype = BSON_SUBTYPE_BINARY;
                    uint32_t binary_len = 0;
                    bson_iter_binary(&iter, &subtype, &binary_len, &binary);
                    string msg;
                    msg.assign((const char*)binary, binary_len);
                    cout << msg << endl;
                }
            }

            3、復(fù)雜的or查詢(xún)和比較查詢(xún)

            //id==4 or field1 <= 12
            bson_t query;
            bson_t child, child2, child3;
            bson_init(&query);
            bson_append_array_begin(&query, "$or", -1, &child);

            //0: 第一個(gè)or部分
            bson_append_document_begin(&child, "0", -1, &child2);
            BSON_APPEND_INT64(&child2, "id", 4);
            bson_append_document_end(&child, &child2);

            //1:第二個(gè)or部分
            bson_append_document_begin(&child, "1", -1, &child2);

            //field1 <= 12
            bson_append_document_begin(&child2, "field1", -1, &child3);
            BSON_APPEND_INT64(&child3, "$lte", 12);
            bson_append_document_end(&child2, &child3);

            bson_append_document_end(&child, &child2);

            bson_append_array_end(&query, &child);

            char * str = bson_as_json(&query, NULL);
            printf("\n%s\n", str);
            posted on 2014-09-27 16:11 merlinfang 閱讀(7518) 評(píng)論(2)  編輯 收藏 引用 所屬分類(lèi): mongodb

            FeedBack:
            # re: mongodb c driver的使用總結(jié)(2)-- 查詢(xún)[未登錄](méi) 2015-03-31 13:37 xxx
            //1:第二個(gè)or部分
            bson_append_document_begin(&child, "1", -1, &child2);
            ===》》》
            bson_append_document_begin(&child, "1", -1, &child3);  回復(fù)  更多評(píng)論
              
            # re: mongodb c driver的使用總結(jié)(2)-- 查詢(xún) 2016-03-28 15:08 aaa
            啊啊啊啊啊  回復(fù)  更多評(píng)論
              
            国产麻豆精品久久一二三| 久久99精品国产麻豆不卡| 久久久久亚洲精品无码网址 | 国产91色综合久久免费| 久久99精品国产麻豆蜜芽| 一97日本道伊人久久综合影院| 久久国产精品久久| 亚洲精品白浆高清久久久久久| 热re99久久精品国产99热| 久久夜色精品国产噜噜噜亚洲AV| 天天做夜夜做久久做狠狠| 久久精品国产只有精品66| 91久久精品无码一区二区毛片| 久久精品国产亚洲av高清漫画| 久久精品国产精品亚洲精品 | 久久久久亚洲AV片无码下载蜜桃| 成人久久免费网站| 亚洲乱码中文字幕久久孕妇黑人| 久久综合丁香激情久久| 亚洲av成人无码久久精品| 久久精品国产国产精品四凭| 久久精品九九亚洲精品| 久久精品一区二区三区AV| 久久综合成人网| 久久一区二区三区99| 精品国产91久久久久久久a| 久久九九精品99国产精品| 一本色道久久88—综合亚洲精品| 伊人久久大香线蕉成人| 模特私拍国产精品久久| 久久国产精品免费一区| 国产精品99久久久久久宅男| 久久国产成人| 成人午夜精品久久久久久久小说| 久久九九亚洲精品| 久久久91精品国产一区二区三区| 新狼窝色AV性久久久久久| 色欲综合久久躁天天躁| 国产ww久久久久久久久久| 品成人欧美大片久久国产欧美...| 国产精品99久久久久久人|