Details
-
New Feature
-
Resolution: Gone away
-
Major - P3
-
None
-
None
-
None
-
None
Description
Hello dear MongoDB guys,
I can visit a mongodb data-base in remote server, get the data-base and correponding collection.
I filter kip with the specific ids, the information can be displayed as the standard string, however, it cannot be queried with the interested keys to get the data-list.
My code is:
int main() {
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
// must remain alive for as long as the driver is in use.
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
mongocxx::instance inst{};mongocxx::client conn{mongocxx::uri{"mongodb://192.168.7.202/#video-label"}};
/* list databases */
for(auto doc : conn.list_databases())Unknown macro: { std}/* access or create a database */
mongocxx::database db = conn["workstation"];
mongocxx::collection collection = db["videolabels"];
/* query one doc that match with filter */
mongocxx::cursor cursor = collection.find(make_document(kvp("id", "m-2417")));
std::string raw_json = "";
for (auto doc : cursor)Unknown macro: { raw_json = bsoncxx}const auto raw_json_length = static_cast<int>(raw_json.length());
JSONCPP_STRING err;
Json::Value root;
Json::CharReaderBuilder builder;
Json::Reader old_reader;if(old_reader.parse(raw_json,root))
Unknown macro: { std}const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
if (!reader->parse(raw_json.c_str(), raw_json.c_str() + raw_json_length, &root,
&err))Unknown macro: { std}std::cout<<root.asString() << std::endl;
const std::string keyboard_str = root["keyboard"].asString();
std::cout<<keyboard_str <<std::endl;
}
As I know, the jsoncpp and other corresponding C++ library can only parse the string with the backslash between double-quote. With standard string as input, I cannot get the "root["keyboard"].asString()". Is there any solution to resolve this? The returned value of bsoncxx and mongocxx API can be queried by jsoncpp.
Thanks & Regards!
Momo