1

I'm using the mongo-cxx-driver-r3.1.1 based on mongo-c-driver-1.6.2. Using the latest examples provided on github, I managed to find how to connect the database and how to save documents.

I'm struggling to fetch results using a filter following the informations provided in the mongocxx/query.cpp example.

There's a lot of call to a make_document method but I have no class/method/template in the bsoncxx namespace with that name (same problem with make_array).

Heres's the includes, the using directives and using declarations :

#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>

#include <mongocxx/instance.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/options/find.hpp>

using namespace mongocxx;
using namespace bsoncxx;

using bsoncxx::builder::basic::document;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::sub_document;
using bsoncxx::builder::basic::sub_array;
using bsoncxx::builder::basic::array;
using bsoncxx::types::value;
using mongocxx::result::insert_one;

The using declarations "not found" :

using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;

Am I missing something obvious ? Are there more recent examples ?

Francois
  • 166
  • 1
  • 10
  • Strange, the `make_document` is in [document.hpp](https://github.com/mongodb/mongo-cxx-driver/blob/master/src/bsoncxx/builder/basic/document.hpp) and the `make_array` is in [array.hpp](https://github.com/mongodb/mongo-cxx-driver/blob/master/src/bsoncxx/builder/basic/array.hpp) which you both included. Could you please provide the actual error message of your compiler? – Andre Kampling Jun 14 '17 at 09:51
  • Thank you ! You helped me notice that my document.hpp doesn't contain the make_document template (and array.hpp the make_array template). I'm going to add them and test this afternoon. I'll keep you informed. – Francois Jun 14 '17 at 10:20

1 Answers1

0

Your code looks right, as you included all necessary header files needed for make_document and make_array. You said in your comment, that the document.hpp doesn't contain the make_document and the array.hpp doesn't contain the make_array template. This is right for the release mongo-cxx-driver-r3.1.1.

In the current master branch the header files exists as you can see if you follow the source links for them: document.hpp and array.hpp. The examples you use are probably for the new master branch as they are also from a current branch from git.

Andre Kampling
  • 5,476
  • 2
  • 20
  • 47
  • The source code comes from the latest release (r3.1.1) from the [mongocxx github release page][1]. [1]: https://github.com/mongodb/mongo-cxx-driver/releases – Francois Jun 14 '17 at 12:53
  • I noticed the link to the hpp files you provided leads to the master branch. The thing is the stable release i'm using is on the stable/release branch. I can't find the commit where the templates were added, but it explains why I couldn't find them. Many thanks for you help. – Francois Jun 14 '17 at 12:54
  • @Francois: Yeah you're right, they're not in the release branch. They should mention that in the examples, strange thing... – Andre Kampling Jun 14 '17 at 12:59