C Driver,如何获取Document Fileds Data对象而不转换为json字符串

时间:2016-03-01 20:43:15

标签: mongodb mongodb-c

当我执行简单的“查找”操作时,我使用C驱动程序在mongoDB上进行操作 如下所示:

while (mongoc_cursor_next (cursor, &doc)) {
     str = bson_as_json (doc, NULL);
     printf ("%s\n", str);
     bson_free (str);
}

我想知道是否有任何方法可以获取bson对象而不转换为json字符串,如此处所示的c ++驱动程序所示:
https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/bsoncxx/getting_values.cpp

auto doc = build_doc.view();


// Once we have the document view, we can use ["key"] or [index] notation to reach into nested
// documents or arrays.
auto awards = doc["awards"];
auto first_award_year = awards[0]["year"];
auto second_award_year = doc["awards"][1]["year"];
auto last_name = doc["name"]["last"];


// If the key doesn't exist, or index is out of bounds, we get invalid elements.
auto invalid1 = doc["name"]["middle"];
auto invalid2 = doc["contribs"][1000];

0 个答案:

没有答案