mongo-cxx-driver

Query nested BSON documents with mongo c++ driver

筅森魡賤 提交于 2019-12-13 17:24:55
问题 I have a bsoncxx::document::view bsonObjView and a std::vector<std::string> path that represents keys to the value we are searching for in the BSON document (first key is top level, second key is depth 1, third key depth 2, etc). I'm trying to write a function that given a path will search the bson document: bsoncxx::document::element deepFieldAccess(bsoncxx::document::view bsonObj, const std::vector<std::string>& path) { assert (!path.empty()); // for each key, find the corresponding value

Why is there an access violation on connecting to MongoDB from C++?

允我心安 提交于 2019-12-13 09:00:48
问题 When I try to run this little piece of code #include <iostream> #include <bsoncxx/builder/stream/document.hpp> #include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mongocxx/instance.hpp> int main(int argc, char **argv) { mongocxx::client client{mongocxx::uri{}}; mongocxx::database db = client["xyz"]; std::cout << "Connected to xyz." << std::endl; } I always get this warning Exception thrown at 0x00007FFF7815F1FD (libmongoc-1.0.dll) in Test.exe: 0xC0000005: Access violation

How to use MongoDB GeoSpatial Index in C++

核能气质少年 提交于 2019-12-12 23:26:59
问题 In python, pymongo provides nice support for MongoDB GeoSpatial index. However, for C++ when I use mongocxx in C++, I am a little bit confused about the grammar. For example, in python (pymongo) I used cursor = db.colection.find( { "loc": { "$near": [lon, lat] } } ).limit(10) to get nearest 10 items for given location. But how can I do the same thing in C++? I tried: mongocxx::cursor cursor = coll.find(document{} << "loc" << open_document << "$near" << [lon, lat] << close_document << finalize

Unset Document::element, MongoCXX Find Option Projection

☆樱花仙子☆ 提交于 2019-12-12 17:08:53
问题 Following is the code trying to use mongo query with project find option. using bsoncxx::builder::stream::document; mongocxx::options::find opts; document condition, options; const static int readdomain = 90000; condition << "lastRead" << open_document << "$gte" << readdomain << close_document; options << "read" << 1; opts.projection(options.view()); mongocxx::cursor cursor = collection.find(condition.view(), opts); The above query without "opts" can work well while the one with "opts" will

Generating Visual Studio 2017 projects with CMake

限于喜欢 提交于 2019-12-12 05:29:29
问题 I tried to build Mongo C++11 drivers for use in my project. The Mongo drivers compiles fine. Instruction on using them insist that when using for own project the following piece of code should also be part of the .vcxproj of my project (if one use Visual Studio, which I do on Windows 10 64bit). <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <LinkIncremental>true</LinkIncremental> <IncludePath>c:\local\boost_1_59_0\;C:\mongo-cxx-driver\include\mongocxx\v_noabi;C:\mongo

find in BSON documents with MongoDB C++ driver

女生的网名这么多〃 提交于 2019-12-12 03:53:25
问题 I have the following document in my MongoDB test database: db.a.find() {[ { "_id" : ObjectId("5113d680732fb764c44qweq"), "Builds" : [ { "level" : 1, "rank" : 2 }, { "level" : 3, "rank" : 4 } ], "abs" : [ { "level" : 3, "status" : 5 }, { "level" : 3, "status" : 4 } ] }, { "_id" : ObjectId("5113d680732fb764c4464fdf"), "Builds" : [ { "level" : 3, "rank" : 5 }, { "level" : 3, "rank" : 4 } ], "abs" : [ { "level" : 3, "status" : 5 }, { "level" : 3, "status" : 4 } ] } ]} I need find Builds level >=2

Build a c++ project with mongodb

末鹿安然 提交于 2019-12-11 19:29:54
问题 I want to save measurements in a mongoDB document and use this data in further operations. I have followed the steps described in this comment by Joyo Waseem to install the needed driver. However, I still get several Error Messages (82 to be specific) in some of the files (alignment_of.hpp; is_nothrow_move_assignable.hpp; view_or_value.hpp; types.hpp; etc). These are just some files which create an error. The error-messages are: Severity Code Line Description Error (active) E0243 36 class or

MongoDB Python and C++ clients - error with multiple instances

回眸只為那壹抹淺笑 提交于 2019-12-11 11:24:43
问题 I'm still new to the MongoDB. My test C++ application is composed from a number of object files, and two of them have their own MongoDB instances. I've found that was a mistake, cause I've got an exception: terminate called after throwing an instance of 'mongocxx::v_noabi::logic_error' what(): cannot create a mongocxx::instance object if one has already been created Aborted (core dumped) So, I'll try to define a single MongoDB instance in this application. And now I worry about my another

Extract key attributes mongocxx

核能气质少年 提交于 2019-12-11 07:25:00
问题 I am trying to extract only key attributes through mongocxx but using find() and find_one() function .I am not able to pull only key values. int main(int, char**) { mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{}}; auto collection = conn["test"]["restaurants"]; bsoncxx::stdx::optional<bsoncxx::document::value> maybe_result =collection.find_one(document{} << finalize); if(maybe_result) { std::cout <<bsoncxx::to_json(*maybe_result)<< "\n"; } } Above code pull only the one

How to generate Mongodb documents recursively using mongocxx c++ driver?

霸气de小男生 提交于 2019-12-11 01:48:57
问题 How to generate Mongodb documents recursively using mongocxx c++ driver? 1. I use mongocxx c++ driver v.3 and c++11. 2. Here is my main.cpp method, which parses hex string and generate mongocxx code like this: console:$ ./main dissect 0x160301012c01000128030340c70e243001b96d8c and the output: << "MainType" << bsoncxx::builder::stream::open_document << "TLSRecord" << bsoncxx::builder::stream::open_document << "type"<< "16" << "version"<< "0301" << "length"<< "012C" << "hsMsg" << bsoncxx: