• <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
            <2006年11月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(9)

            隨筆分類

            隨筆檔案

            文章檔案

            相冊

            搜索

            •  

            積分與排名

            • 積分 - 295931
            • 排名 - 87

            最新評論

            閱讀排行榜

            評論排行榜

            1、查詢樣例

            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查詢和比較查詢

            //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: 第一個or部分
            bson_append_document_begin(&child, "0", -1, &child2);
            BSON_APPEND_INT64(&child2, "id", 4);
            bson_append_document_end(&child, &child2);

            //1:第二個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 閱讀(7538) 評論(2)  編輯 收藏 引用 所屬分類: mongodb

            FeedBack:
            # re: mongodb c driver的使用總結(jié)(2)-- 查詢[未登錄] 2015-03-31 13:37 xxx
            //1:第二個or部分
            bson_append_document_begin(&child, "1", -1, &child2);
            ===》》》
            bson_append_document_begin(&child, "1", -1, &child3);  回復(fù)  更多評論
              
            # re: mongodb c driver的使用總結(jié)(2)-- 查詢 2016-03-28 15:08 aaa
            啊啊啊啊啊  回復(fù)  更多評論
              
            亚洲精品成人久久久| 18岁日韩内射颜射午夜久久成人| 久久精品免费大片国产大片| 青青青青久久精品国产h久久精品五福影院1421 | 狠狠人妻久久久久久综合蜜桃| 99久久婷婷国产一区二区| 欧美粉嫩小泬久久久久久久| 无码伊人66久久大杳蕉网站谷歌| 91精品国产综合久久婷婷| 看全色黄大色大片免费久久久| 久久综合噜噜激激的五月天| 久久无码AV中文出轨人妻| 色婷婷久久综合中文久久蜜桃av| 亚洲午夜久久影院| 久久精品一区二区三区AV| 久久国产综合精品五月天| 亚洲人成精品久久久久| 久久综合伊人77777| 久久国产乱子伦精品免费强| 一本色道久久综合狠狠躁| 久久久久久极精品久久久| 亚洲国产精品一区二区久久| 欧美黑人又粗又大久久久| 热RE99久久精品国产66热| 一级做a爱片久久毛片| 国产V亚洲V天堂无码久久久| 午夜精品久久久久久久久| 少妇人妻综合久久中文字幕| 怡红院日本一道日本久久| 久久久久久久久无码精品亚洲日韩| 久久国产AVJUST麻豆| 久久一本综合| 久久人人爽人人爽人人片AV麻豆| 久久国产精品无码网站| 久久国产美女免费观看精品| 久久精品成人欧美大片| 久久久久18| 久久久久亚洲AV片无码下载蜜桃 | 久久这里只精品99re66| 亚洲欧美一区二区三区久久| 久久这里只精品99re66|