标签: mongo-cxx-driver

加载共享库时出错:libbsoncxx.so._noabi:无法打开共享对象文件:没有这样的文件或目录

我安装了 mongocxx 驱动程序,如http://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/所示,当我测试驱动程序时,一切看起来都很好,但如果更改一点代码,我会收到错误加载共享库:libbsoncxx.so._noabi:无法打开共享对象文件:没有这样的文件或目录

代码:

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

if(POLICY CMP0025)
    cmake_policy(SET CMP0025 NEW)
endif()

project(test_mongodb LANGUAGES C CXX)

if(NOT DEFINED CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 11)
endif()

set(CMAKE_PREFIX_PATH CMAKE_PREFIX_PATH "~/opt/mongo-cxx-driver/install")
set(CMAKE_CXX_EXTENSIONS OFF)

if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()


add_executable(test_mongodb main.cpp)

find_package(libmongocxx REQUIRED)

target_include_directories(test_mongodb
        PRIVATE ${LIBMONGOCXX_INCLUDE_DIRS}
        )

target_link_libraries(test_mongodb
        PRIVATE ${LIBMONGOCXX_LIBRARIES}
        )

target_compile_definitions(test_mongodb
        PRIVATE ${LIBMONGOCXX_DEFINITIONS}
        )

add_custom_target(run
        COMMAND test_mongodb
        DEPENDS test_mongodb
        WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
        )

list(FIND LIBMONGOCXX_DEFINITIONS "BSONCXX_STATIC" LIST_IDX)
if (${LIST_IDX} GREATER -1)
    message(FATAL_ERROR "Expected BSONCXX_STATIC to not be …
Run Code Online (Sandbox Code Playgroud)

c++ mongodb mongo-cxx-driver

6
推荐指数
1
解决办法
2953
查看次数

如何使用c ++驱动程序将mongodb数组保存到向量中?

例如,如果我在shell中执行此操作

> db.numbers.save( { name: "fibonacci", arr: [0, 1, 1, 2, 3, 5, 8, 13, 21] } )
Run Code Online (Sandbox Code Playgroud)

然后我想进入arr我的c ++程序.

之后,我得到了我BSONObj可以得到name

std::string name = p.getStringField("name");
Run Code Online (Sandbox Code Playgroud)

pBSON对象在哪里.

但是从数组中获取元素并将它们保存到std :: vector的正确方法是什么?

编辑:

经过一些研究后,我发现了BSONElement doxygen文档并做了这个.

std::vector<int> arr;
std::vector<BSONElement> v = p.getField("arr").Array();
for(std::vector<BSONElement>::iterator it = v.begin(); it != v.end(); ++it)
    arr.push_back(it->numberInt());
Run Code Online (Sandbox Code Playgroud)

但我仍然不确定这是否正确.

c++ mongodb bson mongo-cxx-driver

5
推荐指数
1
解决办法
3811
查看次数

mongoDB c ++ 11驱动程序获取插入文档的ID

我正在使用新的c ++ 11 mongoDB驱动程序(不是旧版驱动程序).

我在插入新文档后试图在mongoDB中获取文档的"id".此ID位于返回值"retVal3"中.

    struct core::v1::optional<mongocxx::v_noabi::result::insert_one> retVal3 = collection.insert_one(document.view());
Run Code Online (Sandbox Code Playgroud)

这是没有auto命令的操作.我希望Eclipse能够解决这个问题并帮助我从中获取ID.不工作.

调试时我可以看到ID.它保存在12字节数组中.以十六进制显示它显示ID.这个结构深入到这个结构中.

retVal3 ==> core::v1::impl::storage<mongocxx::v_noabi::result::insert_one, false> ==>

val ==> _generated_id ==> _b_oid ==> value ==> _bytes ==> _M_elems char [12]
Run Code Online (Sandbox Code Playgroud)

我不知道如何从这个结构/对象中获取这12个字节.它是一个对象吗?

是否存在功能?你知道另一种方法吗?

谢谢

document get mongodb c++11 mongo-cxx-driver

5
推荐指数
1
解决办法
1314
查看次数

何时在mongodb cxx r3.0.2驱动程序中使用finalize

我很困惑,在在线文档的代码片段中,它显示了调用update_many方法时finalize的用法,如下所示:

mongocxx::stdx::optional<mongocxx::result::update> result =
 collection.update_many(
  document{} << "i" << open_document <<
    "$lt" << 100 << close_document << finalize,
  document{} << "$inc" << open_document <<
    "i" << 100 << close_document << finalize);
Run Code Online (Sandbox Code Playgroud)

但我已经看到mongocxx驱动程序代码中的示例代码没有finalize

  // Update multiple documents.
    {
        // @begin: cpp-update-multiple-documents
        bsoncxx::builder::stream::document filter_builder, update_builder;
        filter_builder << "address.zipcode"
                       << "10016"
                       << "cuisine"
                       << "Other";
        update_builder << "$set" << open_document << "cuisine"
                       << "Category To Be Determined" << close_document << "$currentDate"
                       << open_document << "lastModified" << true << close_document; …
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query mongo-cxx-driver

5
推荐指数
1
解决办法
215
查看次数

Mongodb C++ 正则表达式查询

如何在 C++ 中使用正则表达式查询 MongoDB 数据库。

mongo-cxx-driver-r3.1.1

听到包括

#include <cstdlib>
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <cstdint>
#include <vector>
#include <mongocxx/stdx.hpp>
#include <bson.h>
#include <conio.h> 
#include <sstream> 
#include <stdio.h> 
#include <string>
#include <bsoncxx/types.hpp>
#include <mongocxx/exception/exception.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>

using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的。

  void MyClass::on_querybtn_clicked()
   {

auto collection = conn["TestDB"]["fdevices"];
bsoncxx::types::b_regex::b_regex();//i am lost here dont know how to use it
auto cursor = collection.find({});

 for …
Run Code Online (Sandbox Code Playgroud)

c++ regex mongodb mongo-cxx-driver

5
推荐指数
1
解决办法
697
查看次数

MongoDB C++:mongocxx :: pool线程安全吗?

获取连接时是否必须手动锁定mongocxx :: pool?

即这样安全吗?(从Mongo网站复制的例子)

mongocxx::instance instance{};
mongocxx::pool pool {mongocxx::uri{}};

using mongocxx::pool::entry = std::unique_ptr<client, std::function<void (client*)>>

auto threadfunc = [](mongocxx::client &client, stdx::string_view dbname) {
    client[dbname]["col"].insert({});
}
// don't even bother sharing clients. Just give each thread its own,
std::thread([]() {
    // pool.acquire() returns a mongo::pool::entry type
    mongocxx::client *c= pool.acquire().get();
    threadfunc(*c, "db1");
    threadfunc(*c, "db2");
});

std::thread([]() {
    mongocxx::client *c = pool.acquire().get();;
    threadfunc(*c, "db2");
    threadfunc(*c, "db1");
});
Run Code Online (Sandbox Code Playgroud)

c++ multithreading mongodb mongo-cxx-driver

4
推荐指数
1
解决办法
1141
查看次数

使用 CMakeExternalProject_Add 构建 mongo-cxx-driver

我正在尝试构建mongo-cxx-driver一个基于 CMake 的项目。这个项目应该在 Windows、macOS 和 ubuntu 容器中构建,我想确保所有这些平台上的软件将使用相同的驱动程序版本,因此我无法通过 等方式安装驱动程序及其依赖项。apt-get所以brew我只剩下一个选项:ExternalProject_Add。但鉴于设置方式,我很难完成这项工作libmongoc。下面是我目前拥有的 CMake 模块。

include(ExternalProject)

set(libmongoc_CMAKE_ARGS
    "-DCMAKE_BUILD_TYPE:STRIING=${CMAKE_BUILD_TYPE}"
    "-DENABLE_TESTS:BOOL=OFF"
    "-DENABLE_STATIC:BOOL=OFF"
    "-DENABLE_EXAMPLES:BOOL=OFF"
    "-DENABLE_EXTRA_ALIGNMENT:BOOL=OFF"
)

set(mongocxx_CMAKE_ARGS
    "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
    "-DCMAKE_BUILD_TYPE:STRIING=${CMAKE_BUILD_TYPE}"
    "-DBUILD_SHARED_LIBS:BOOL=ON"
    "-DENABLE_TESTS:BOOL=OFF"
    "-DENABLE_EXAMPLES:BOOL=OFF"
    "-DBSONCXX_POLY_USE_BOOST:BOOL=ON"
    "-DBSONCXX_POLY_USE_MNMLSTC:BOOL=OFF"
    "-Dlibbson-1.0_DIR:PATH=${OTS_DEPDENDENCIES_DIR}/libmongoc/src/libbson"
)

if (NOT TARGET libmongoc)
    ExternalProject_Add(
        libmongoc
        GIT_REPOSITORY  "https://github.com/mongodb/mongo-c-driver.git"
        GIT_TAG         "1.12.0"
        SOURCE_DIR      "${OTS_DEPDENDENCIES_DIR}/libmongoc"
        BINARY_DIR      "${OTS_DEPDENDENCIES_DIR}/libmongoc"
        CMAKE_ARGS      "${libmongoc_CMAKE_ARGS}"
        INSTALL_COMMAND ""
    )
endif()

if (NOT TARGET mongocxx)
    ExternalProject_Add(
        mongocxx
        GIT_REPOSITORY  "https://github.com/mongodb/mongo-cxx-driver.git"
        GIT_TAG         "r3.3.1"
        SOURCE_DIR      "${OTS_DEPDENDENCIES_DIR}/mongocxx"
        BINARY_DIR      "${OTS_DEPDENDENCIES_DIR}/mongocxx"
        CMAKE_ARGS      "${mongocxx_CMAKE_ARGS}"
        INSTALL_COMMAND ""
        DEPENDS         libmongoc
    )
endif() …
Run Code Online (Sandbox Code Playgroud)

c++ cmake mongodb mongo-cxx-driver

4
推荐指数
1
解决办法
2931
查看次数

如何在 Visual Studio 中使用 mongodb-cxx-driver 设置项目

我已经使用 Visual Studio 在 Windows 上成功构建了新的 libmongo-cxx-driver,但我不明白如何在 VS 2015 中设置项目以链接到它。我将不胜感激。

c++ mongodb mongo-cxx-driver visual-studio-2015

3
推荐指数
1
解决办法
2124
查看次数

MongoDB C ++,如何在插入时添加ISODate值

这是关于新的MongoDB C ++驱动程序(不是旧版驱动程序)。我可以这样插入文档:

value Value = document{}
<<"Key" <<"Value"
<<finalize;

cxxClient["db"]["collection"].insert_one(Value.view());
Run Code Online (Sandbox Code Playgroud)

上面的代码插入一个文档,该文档具有值为'Value'的1个字段'Key'。我可以插入字符串,整型,浮点型...,但无法弄清楚如何插入ISODate。新的MongoDB C ++驱动程序应在文档中附带更多示例。

c++ mongodb isodate mongodb-query mongo-cxx-driver

3
推荐指数
1
解决办法
1154
查看次数

在 Docker 中安装 Mongo c 和 c++ 驱动程序

我正在尝试在 Docker 容器中安装 mongocxx 驱动程序,第一步是使用包管理器安装 mongo-c 驱动程序。我精简的 Dockerfile:

FROM phusion/baseimage:latest
RUN apt-get install -y libmongoc-1.0-0
Run Code Online (Sandbox Code Playgroud)

在这一步之后,我应该准备好按照这里的说明安装 cxx 驱动程序:https : //mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/

RUN git clone https://github.com/mongodb/mongo-cxx-driver.git  --branch releases/stable --depth 1
WORKDIR /mongo-cxx-driver/build
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
RUN make EP_mnmlstc_core
RUN make && make install
Run Code Online (Sandbox Code Playgroud)

这一直持续到 cmake 步骤失败,无法找到 libbson 包

Step 17/25 : RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
 ---> Running in ba6033b680bb
-- The CXX compiler identification is GNU 5.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working …
Run Code Online (Sandbox Code Playgroud)

mongo-c-driver docker mongo-cxx-driver

3
推荐指数
1
解决办法
1333
查看次数