我想看看使用C++ 3.0驅動程序從MongoDB中檢索單個文檔的結果。 driver documentation描述了bsoncxx::document::value類的view() method(其由mongocxx::collection::find_one返回)。當我嘗試使用這樣的:無法調用bsoncxx :: document :: value :: view()
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/document/value.hpp>
#include <mongocxx/instance>
#include <mongocxx/client>
mongocxx::instance inst{};
mongocxx::client conn{};
bsoncxx::document::view doc;
auto db = conn["test"];
try {
auto docObj = db["collection"].find_one(document{} <<
"field" << "value" << finalize);
doc = docObj.view();
} catch (mongocxx::exception::query e) {
std::cerr << "Couldn't retrieve document";
return NULL;
}
...
我得到以下編譯錯誤:
error: 'struct core::v1::optional<bsoncxx::v0::document::value>' has no member named 'view'
在該行
doc = docObj.view();
我在做什麼錯?如果這不是使用find_one()
的正確方式,我應該用什麼來代替?
-1我不知道你想在這裏說什麼。請刪除您的關於無法評論的信息,並將其清除爲完整的答案,並解釋您正在嘗試解決的問題。就目前而言,我認爲你正試圖指出一個問題,它並不完全存在(由try catch塊處理)。 –