天道酬勤,学无止境

Using declaration "not found" in mongodb c++ driver

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 ?

标签

评论

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.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • 在 Windows 中构建 MongoDB C 驱动程序(Building MongoDB C Driver in Windows)
    问题 到目前为止我所做的 我阅读了安装指南。 下载安装文件后为 Windows 安装了 OpenSSL 库。 从 GitHub 下载并解压缩 Mongo C 驱动程序目录。 从 CMake 网站下载后安装 CMake for Windows。 转到mongo-c-driver/src/libbson并运行cmake -G "Visual Studio 14 2015 Win64"并打印(可能)成功。 D:\works\test\mongo-c-driver\src\libbson>cmake -G "Visual Studio 14 2015 Win64" Current version (from VERSION_CURRENT file): 1.4.0-dev Previous release (from VERSION_RELEASED file): 1.3.5 -- Check if the system is big endian -- Searching 16 bit integer -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h --
  • 在 Cygwin 上编译 MongoDB C++ 驱动程序(Compiling MongoDB C++ driver on Cygwin)
    问题 我尝试使用“scons”命令在 Cygwin 上编译 MongoDB C++ 驱动程序,但出现以下错误: src/mongo/db/nonce.cpp:48:20: error: ‘srandomdev’ was not declared in this scope 那是什么lib? 谢谢。 回答1 srandomdev 函数在 BSD 或 OSX 系统上的stdlib.h 中可用,而不是在 Cygwin 或 Linux 等 GNU 系统上可用。 看起来构建脚本无法识别您在 Cygwin 上运行的事实。 您可以尝试几个选项。 最简单的是 更改 ifdef 子句 如果没有 Windows 机器来测试这个,很难确认这对你有用。 在src/mongo/platform/random.cpp 中,编辑第 108 行 #elif defined(__linux__) || defined(__sunos__) || defined(__APPLE__) 成为 #elif defined(__linux__) || defined(__sunos__) || defined(__APPLE__) || defined(__CYGWIN__) 删除最后一个 else 子句 找到如下所示的src/mongo/platform/random.cpp行(在我的版本中为 141) #else
  • Compiling MongoDB C++ driver on Cygwin
    I junt trying compile the MongoDB C++ driver on Cygwin with the 'scons' command and i getting this follow error: src/mongo/db/nonce.cpp:48:20: error: ‘srandomdev’ was not declared in this scope What lib is that? Thanks.
  • 使用 mongodb 构建一个 C++ 项目(Build a c++ project with mongodb)
    问题 我想将测量值保存在 mongoDB 文档中,并在进一步的操作中使用这些数据。 我已按照 Joyo Waseem 在此评论中描述的步骤安装所需的驱动程序。 但是,我仍然在某些文件(alignment_of.hpp;is_nothrow_move_assignable.hpp;view_or_value.hpp;types.hpp;等)中收到几个错误消息(具体来说是 82 条)。 这些只是一些会产生错误的文件。 错误消息是: Severity Code Line Description Error (active) E0243 36 class or struct definition is missing Error (active) E1574 29 static assertion failed with "Arguments to is_nothrow_move_constructible must be complete types" Error (active) E0070 31 incomplete type is not allowed Error (active) E1574 31 static assertion failed with "Arguments to is_nothrow_move_assignable must be complete
  • Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
    I am trying to install the MongoDB C++ driver on my machine. I have followed the directions here, and everything seemed to install successfully. Still, I can't seem to include the headers. Here is a simple test program: #include <cstdlib> #include <iostream> #include "mongo/client/dbclient.h" void run() { mongo::DBClientConnection c; c.connect("localhost"); } int main() { try { run(); std::cout << "connected ok" << std::endl; } catch(const mongo::DBException &e) { std::cout << "caught" << e.what() << std::endl; } return EXIT_SUCCESS; } Here are the errors I get: g++ app/tutorial.cpp -pthread
  • 如何使用mongodb的c ++驱动程序构建程序?(How can I build a program using c++ driver of mongodb?)
    问题 请告诉我如何使用mongodb的c ++驱动程序来构建程序。 我的英语不好也没什么大不了的。 我的环境 Windows7 64位 Visual Studio Ultimate 2012(x64发布目标项目) 我执行了以下步骤。 我安装了Ptython 2.7.2,适用于Windows的Python扩展和Scons 2.3.0。 我安装了Boost 1.54.0。 我执行了'boostrap'和'b2 -a --build-type = complete --address-model = 64 --link = static --runtime-link = static' 我下载了mongodb-linux-x86_64-v2.4-latest.tgz。 我在SConstruct中添加了以下文本。 env.Append(CPPPATH=['C:\\boost\\boost_1_54_0']) env.Append(LIBPATH=['C:\\boost\\boost_1_54_0\\stage\\lib']) env.Append(CPPDEFINES=["_UNICODE"]) env.Append(CPPDEFINES=["UNICODE"]) 我执行了“ scons mongoclient”。 我做了一个Visual Studio C ++的项目。 我在项目中设置了“
  • Using the mongodb cxx driver in a cmake c++ project
    I am new to cmake and I want to connect to a mongodb using c++ and the latest mongodb cxx driver. I managed to compile and install the driver but now I stuck with using it in my cmake project. I installed the mongodb driver with the default settings, so it's located under /usr/local/lib/include/mongocxx/v_noabi/mongocxx. In my cmake file i manged to get the includes resolved with: include_directories(/usr/local/lib/include/mongocxx/v_noabi /usr/local/lib/include/bsoncxx/v_noabi) but I don't know how to actually link the driver libs to my executable. Could any one please help me?
  • 无法使用带有 MSVC 的 mongodb c++ 驱动程序构建项目(Can't build project using mongodb c++ driver with MSVC)
    问题 我正在尝试使用 Visual Studio 构建以下示例 C++ 代码: #include <iostream> #include <bsoncxx/builder/stream/document.hpp> #include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mongocxx/instance.hpp> int main(int, char**) { mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{}}; bsoncxx::builder::stream::document document{}; auto collection = conn["testdb"]["testcollection"]; document << "hello" << "world"; collection.insert_one(document.view()); auto cursor = collection.find({}); for (auto&& doc : cursor) { std::cout << bsoncxx::to_json(doc) << std::endl; } } 我没有收到任何代码错误
  • Building and installing MongoDB C++ driver in OS X
    I have downloaded the latest version of MongoDB C++ driver for my os x from http://dl.mongodb.org/dl/cxx-driver. Then I extracted using tar xvf command in os x terminal. After that I run scons to build the driver. It build successfully by giving following messages -- some messages -- ranlib build/libmongoclient.a ranlib: file: build/libmongoclient.a(backtrace.o) has no symbols ranlib: file: build/libmongoclient.a(posix_fadvise.o) has no symbols ranlib: file: build/libmongoclient.a(ssl_manager.o) has no symbols Install file: "build/libmongoclient.a" as "libmongoclient.a" scons: done building
  • 如何在 ubuntu 中为 C++ 安装 mongodb 驱动程序?(how to install mongodb drivers for c++ in ubuntu?)
    问题 我想使用 C++ 为 mongoDB 开发一个相当简单的应用程序,我按照他们的教程进行操作:http://www.mongodb.org/pages/viewpage.action?pageId=133415 为了安装驱动程序,我遵循了这个:https://groups.google.com/forum/?fromgroups=#!msg/mongodb-user/-mPG7MDJgm8/nZSiN42DJWIJ(Waitman Gobble/5 jun answer) 但是当我尝试编译一个简单的应用程序时,我会收到以下错误: 致命错误:client/dbclient.h:没有那个文件或目录 我很确定问题是尚未安装 MongoDB c++ 驱动程序。 我怎样才能正确安装它? 回答1 如果您从这里下载驱动程序源代码, 解压并解压 tar xzf mongodb-linux-x86_64-v2.0-latest.tgz 然后cd进入目录。 cd mongo-cxx-driver-v2.0/ 然后使用 scons 构建 scons 并安装 sudo scons install 然后要编译教程中显示的代码,您还需要指定 /usr/local/include/mongo 目录作为包含文件搜索路径。 sudo g++ tutorial.cpp -I/usr/local/include
  • 在 OS X 中构建和安装 MongoDB C++ 驱动程序(Building and installing MongoDB C++ driver in OS X)
    问题 我已经从 http://dl.mongodb.org/dl/cxx-driver 为我的 os x 下载了最新版本的 MongoDB C++ 驱动程序。 然后我在 os x 终端中使用 tar xvf 命令提取。 之后我运行 scons 来构建驱动程序。 它通过提供以下消息成功构建 -- some messages -- ranlib build/libmongoclient.a ranlib: file: build/libmongoclient.a(backtrace.o) has no symbols ranlib: file: build/libmongoclient.a(posix_fadvise.o) has no symbols ranlib: file: build/libmongoclient.a(ssl_manager.o) has no symbols Install file: "build/libmongoclient.a" as "libmongoclient.a" scons: done building targets. 所以,然后我运行命令“scons install”将库安装到我的机器中。 --some messages -- scons: done reading SConscript files. scons: Building
  • 在 cmake c++ 项目中使用 mongodb cxx 驱动程序(Using the mongodb cxx driver in a cmake c++ project)
    问题 我是 cmake 的新手,我想使用 c++ 和最新的 mongodb cxx 驱动程序连接到 mongodb。 我设法编译并安装了驱动程序,但现在我坚持在我的 cmake 项目中使用它。 我使用默认设置安装了 mongodb 驱动程序,因此它位于 /usr/local/lib/include/mongocxx/v_noabi/mongocxx 下。 在我的 cmake 文件中,我设法通过以下方式解决了包含: include_directories(/usr/local/lib/include/mongocxx/v_noabi /usr/local/lib/include/bsoncxx/v_noabi) 但我不知道如何将驱动程序库实际链接到我的可执行文件。 任何人都可以帮助我吗? 回答1 你不应该这样做。 您可以并且应该通过 CMake 的 find_package 或 pkg_check_modules 子系统找到 C++11 驱动程序。 C++11 驱动程序支持两者。 回答2 我已经完成了链接 mongocxx 驱动程序文档中链接的所有内容并使用 CMake 'find_package': find_package(libmongocxx REQUIRED) find_package(libbsoncxx REQUIRED) include_directories($
  • 安装mongo-c-driver和mongo-cxx-driver中遇到的部分问题及解决办法
    一、安装mongodb 请安官网安装即可: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ 二、安装mongo-c-driver中可能会遇到的问题 1、如果安装mongo-cxx-driver时出现找不到libmongoc,libbson,等。请确定自己是否按照官网教程正确安装了mongo-c-driver. 在安装mongo-cxx-driver时,如果出现 not find libmongc-1.0-0, libmongoc, libbson 请确定是否正确安装mongo-c-driver,只有正确安装mongo-c-driver才会自动安装libmongc-1.0-0。其他的请按照官网教程正确安装(请不要忽略安装中最后出现的error,很可能就是没有装上)。 http://mongoc.org/libmongoc/current/installing.html (官网教程,这句是在安装mongo-cxx-driver时遇见的问题回溯到这里) 如果未正常安装,请需要重新安装mongo-c-driver 2、其中可能出现了以下报错 /usr/bin/ld: /usr/local/lib/libsnappy.a(snappy.cc.o): undefined reference to
  • Build a c++ project with mongodb
    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 struct definition is missing Error (active) E1574 29 static assertion failed with "Arguments to is
  • How to generate Mongodb documents recursively using mongocxx c++ driver?
    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::builder::stream::open_document << "type"<< "01" << "length"<< "000128" << "clientHello" << bsoncxx::builder
  • how to install mongodb drivers for c++ in ubuntu?
    I want to develop a fairly simple application using c++ for mongoDB and I follow their tutorials : http://www.mongodb.org/pages/viewpage.action?pageId=133415 and for installing driver I followed this one : https://groups.google.com/forum/?fromgroups=#!msg/mongodb-user/-mPG7MDJgm8/nZSiN42DJWIJ (Waitman Gobble/5 jun answer) but yet when I try to compile a simple application I will get following error : fatal error: client/dbclient.h: No such file or directory I'm pretty sure the problem is MongoDB c++ driver hasn't installed yet. How can I install it properly?
  • How can I build a program using c++ driver of mongodb?
    Please tell me how to build a program using c++ driver of mongodb. No flames about my bad English. My Environment Windows7 64bit Visual Studio Ultimate 2012 (x64 Release target project) I performed the following steps. I installed Ptython 2.7.2, Python for Windows extensions and Scons 2.3.0. I installed boost 1.54.0. I perfomed 'boostrap' and 'b2 -a --build-type=complete --address-model=64 --link=static --runtime-link=static' I download mongodb-linux-x86_64-v2.4-latest.tgz. I added the following texts to SConstruct. env.Append(CPPPATH=['C:\\boost\\boost_1_54_0']) env.Append(LIBPATH=['C:\\boost
  • Can't build project using mongodb c++ driver with MSVC
    I'm trying to build the following sample c++ code with Visual Studio: #include <iostream> #include <bsoncxx/builder/stream/document.hpp> #include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mongocxx/instance.hpp> int main(int, char**) { mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{}}; bsoncxx::builder::stream::document document{}; auto collection = conn["testdb"]["testcollection"]; document << "hello" << "world"; collection.insert_one(document.view()); auto cursor = collection.find({}); for (auto&& doc : cursor) { std::cout << bsoncxx::to_json(doc) << std
  • ambiguous << operator in Mongodb C++ driver document builder
    I am trying to build a mongodb document using the v3 driver. I am using strings from an array of "char *" pointers but I keep getting an error that says the << operator is ambiguous. The exact error is: item.cpp:105: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::enable_if<true, bsoncxx::v_noabi::builder::stream::key_context<> >::type {aka bsoncxx::v_noabi::builder::stream::key_context<>}’ and ‘const char*’) << dbTypeString[dbType::IT_TYPE] dbTypeString is an array of strings like: const char * dbTypeString[] = {"string a", "string b"} a simplified version of the mongo
  • 如何使用 mongocxx C++ 驱动程序递归生成 Mongodb 文档?(How to generate Mongodb documents recursively using mongocxx c++ driver?)
    问题 如何使用 mongocxx C++ 驱动程序递归生成 Mongodb 文档? 1. 我使用 mongocxx c++ 驱动程序 v.3 和 c++11。 2. 这是我的 main.cpp 方法,它解析十六进制字符串并生成这样的 mongocxx 代码: console:$ ./main dissect 0x160301012c01000128030340c70e243001b96d8c 和输出: << "MainType" << bsoncxx::builder::stream::open_document << "TLSRecord" << bsoncxx::builder::stream::open_document << "type"<< "16" << "version"<< "0301" << "length"<< "012C" << "hsMsg" << bsoncxx::builder::stream::open_document << "type"<< "01" << "length"<< "000128" << "clientHello" << bsoncxx::builder::stream::open_document << "version"<< "0303" << "random"<< "40C70E243001B96D8C" << "session