- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试使用 C++ Driver 3.1.2,代码仍然在客户端解构器中崩溃
MongoMgr.h
#ifndef _MOMGODB_MANAGER_H_
#define _MOMGODB_MANAGER_H_
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/types.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/exception/exception.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>
#include "ConfFile.h"
using namespace std;
using bsoncxx::builder::basic::kvp;
//using bsoncxx::builder::basic;
//using bsoncxx::builder::basic::make_array;
//using bsoncxx::builder::basic::make_document;
class MongoMgr : boost::noncopyable
{
using string = std::string;
public:
// Constructor function
MongoMgr(string path = "/home/dev/memo_app/server/config_file/MongoConfig.json")
: m_confLib(path)
{
//setPoolConfig();
}
// Deconstructor
// Free all resources
~MongoMgr();
// Manager Initialization
int init();
// Insert single document to database
bool insertSingleDoc(string db, string collect, string doc);
// Insert multiple documents to database
bool insertMultipleDoc(string db, string collect, vector<string> docs);
// Query Documents
string queryDoc(string db, string collect, string conditions);
// Update Documents
// Only update top-level fields in a single document.
// @Conditions should contains unique key
bool updateSingleDoc(string db, string collect, string values, string conditions);
// Update Multiple Documents
bool updateMultipleDoc(string db, string collect, string values, string conditions);
// Replace Documents
// Only replace top-level fields in a single document.
// @Conditions should contains unique key
bool replaceDoc(string db, string collect, string values, string conditions);
// Remove Document
// @isRemoveOne, true stand for remove one document, false stand for remove multiple
bool deleteDoc(string db, string collect, string conditions, bool isDeleteOne = true);
// Get a connection (client) from pool
using connection = mongocxx::pool::entry;
connection getConnection() { return m_ptrPool->acquire(); }
protected:
//set pool configuration before initialize it
void setPoolConfig();
private:
// Mongodb Instance
typedef boost::shared_ptr<mongocxx::instance> mongoInstPtr;
mongoInstPtr m_ptrDbInst;
// Mongodb pool infomation
typedef boost::shared_ptr<mongocxx::uri> mongoUriPtr;
mongoUriPtr m_ptrDbUri;
// Mongodb pool
typedef boost::shared_ptr<mongocxx::pool> mongoPoolPtr;
mongoPoolPtr m_ptrPool;
// Configure file
ConfFile m_confLib;
};
// Glabal variable MongoDB Manager
extern boost::shared_ptr<MongoMgr> g_pMongoMgr;
#endif
插入部分代码崩溃,其余部分尚未测试,所以我上次没有发布,不便之处,敬请谅解。
MongoMgr.cpp
#include "MongoMgr.h"
#include <iostream>
MongoMgr::~MongoMgr()
{
}
int MongoMgr::init()
{
try
{
m_ptrDbInst = boost::shared_ptr<mongocxx::instance>(new mongocxx::instance{});
setPoolConfig();
m_ptrPool = boost::shared_ptr<mongocxx::pool>(new mongocxx::pool{*m_ptrDbUri});
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
exit(0);
}
}
bool MongoMgr::insertSingleDoc(string db, string collect, string doc)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db.c_str()][collect];
auto docContent = bsoncxx::from_json(doc);
collection.insert_one(docContent.view());
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
bool MongoMgr::insertMultipleDoc(string db, string collect, vector<string> docs)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
vector<bsoncxx::document::value> vecDocs;
for (auto strDoc : docs)
{
vecDocs.push_back(bsoncxx::from_json(strDoc));
}
collection.insert_many(vecDocs);
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
string MongoMgr::queryDoc(string db, string collect, string conditions)
{
string ret;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
auto cursor = collection.find(bsoncxx::from_json(conditions));
if (cursor.begin() == cursor.end())
{
return string();
}
ret = "[";
for (auto&& doc : cursor) {
ret += bsoncxx::to_json(doc);
}
ret += "]";
//if (0 == ret.compare("[]")) ret.clear();
return ret;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
ret = "Error";
}
return ret;
}
bool MongoMgr::updateSingleDoc(string db, string collect, string values, string conditions)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
auto docConditions = bsoncxx::from_json(conditions);
auto docValues = bsoncxx::from_json(values);
collection.update_one(docConditions.view(), docValues.view());
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
bool MongoMgr::updateMultipleDoc(string db, string collect, string values, string conditions)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
auto docConditions = bsoncxx::from_json(conditions);
auto docValues = bsoncxx::from_json(values);
collection.update_many(docConditions.view(), docValues.view());
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
bool MongoMgr::replaceDoc(string db, string collect, string values, string conditions)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
auto docConditions = bsoncxx::from_json(conditions);
auto docValues = bsoncxx::from_json(values);
collection.replace_one(docConditions.view(), docValues.view());
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
bool MongoMgr::deleteDoc(string db, string collect, string conditions, bool isDeleteOne)
{
bool bRet;
try
{
auto client = m_ptrPool->acquire();
auto collection = (*client)[db][collect];
auto docConditions = bsoncxx::from_json(conditions);
if (true == isDeleteOne)
{
collection.delete_one(docConditions.view());
}
else if (false == isDeleteOne)
{
collection.delete_many(docConditions.view());
}
bRet = true;
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
bRet = false;
}
return bRet;
}
void MongoMgr::setPoolConfig()
{
string strConfig = "mongodb://";
strConfig += m_confLib["db_ip"].get<string>() + string(":");
strConfig += m_confLib["db_port"].get<string>() + string("/?");
strConfig += string("minPoolSize=") + m_confLib["minPoolSize"].get<string>() + string("&");
strConfig += string("maxPoolSize=") + m_confLib["maxPoolSize"].get<string>();
try
{
m_ptrDbUri = boost::shared_ptr<mongocxx::uri>(new mongocxx::uri{strConfig});
}
catch (const mongocxx::exception & e)
{
std::cout << e.what() << std::endl;
}
}
主要.cpp
#include <boost/shared_ptr.hpp>
#include <string>
#include "MongoMgr.h"
#include <iostream>
using mongoMgrPtr = boost::shared_ptr<MongoMgr>;
// MongoDB manager global pointer
mongoMgrPtr g_pMongoMgr;
#define DB_USED "memotest"
#define COLLECTION "mt"
int main(int argc, char* argv[])
{
// MongoDB manager initailize
g_pMongoMgr = mongoMgrPtr(new MongoMgr());
g_pMongoMgr->init();
string doc = "{\"name\":\"Zed\"}";
bool bInsert = g_pMongoMgr->insertSingleDoc(DB_USED, COLLECTION, doc);
if (true == bInsert) cout << "Insert document successed!" << endl;
//string strQuery = g_pMongoMgr->queryDoc(DB_USED, COLLECTION, jMongoTest.dump());
//cout << strQuery << endl;
return 0;
}
ldd 的输出如下:
linux-vdso.so.1 => (0x00007fffa5b92000)
libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f43c7a7a000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f43c785d000)
librt.so.1 => /lib64/librt.so.1 (0x00007f43c7655000)
libmongocxx.so._noabi => /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi (0x00007f43c7401000)
libbsoncxx.so._noabi => /home/dev/memo_app/dependencies/lib/libbsoncxx.so._noabi (0x00007f43c71e6000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f43c6ede000)
libm.so.6 => /lib64/libm.so.6 (0x00007f43c6bdc000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f43c69c5000)
libc.so.6 => /lib64/libc.so.6 (0x00007f43c6602000)
/lib64/ld-linux-x86-64.so.2 (0x000055d327097000)
libmongoc-1.0.so.0 => /usr/local/lib/libmongoc-1.0.so.0 (0x00007f43c6394000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007f43c6121000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f43c5cc0000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f43c5aa6000)
libz.so.1 => /lib64/libz.so.1 (0x00007f43c588f000)
libbson-1.0.so.0 => /usr/local/lib/libbson-1.0.so.0 (0x00007f43c565a000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f43c540c000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f43c5124000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f43c4f20000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f43c4cec000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f43c4ae8000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f43c48da000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f43c46d5000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f43c44ae000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f43c424b000)
Version information:
./memoSvr:
libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
libstdc++.so.6 (GLIBCXX_3.4.13) => /lib64/libstdc++.so.6
libstdc++.so.6 (CXXABI_1.3) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.14) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.11) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.15) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.5) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4) => /lib64/libstdc++.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
/lib64/libuuid.so.1:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libpthread.so.0:
ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/librt.so.1:
libpthread.so.0 (GLIBC_2.3.2) => /lib64/libpthread.so.0
libpthread.so.0 (GLIBC_PRIVATE) => /lib64/libpthread.so.0
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi:
libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libstdc++.so.6 (CXXABI_1.3) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.11) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.15) => /lib64/libstdc++.so.6
/home/dev/memo_app/dependencies/lib/libbsoncxx.so._noabi:
libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libstdc++.so.6 (CXXABI_1.3) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.15) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4) => /lib64/libstdc++.so.6
libstdc++.so.6 (GLIBCXX_3.4.11) => /lib64/libstdc++.so.6
/lib64/libstdc++.so.6:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
libm.so.6 (GLIBC_2.2.5) => /lib64/libm.so.6
libgcc_s.so.1 (GCC_4.2.0) => /lib64/libgcc_s.so.1
libgcc_s.so.1 (GCC_3.3) => /lib64/libgcc_s.so.1
libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libm.so.6:
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
/lib64/libgcc_s.so.1:
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libc.so.6:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
/usr/local/lib/libmongoc-1.0.so.0:
libz.so.1 (ZLIB_1.2.0) => /lib64/libz.so.1
librt.so.1 (GLIBC_2.2.5) => /lib64/librt.so.1
libresolv.so.2 (GLIBC_2.2.5) => /lib64/libresolv.so.2
libresolv.so.2 (GLIBC_2.9) => /lib64/libresolv.so.2
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.6) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libpthread.so.0 (GLIBC_2.3.2) => /lib64/libpthread.so.0
libssl.so.10 (libssl.so.10) => /lib64/libssl.so.10
libcrypto.so.10 (libcrypto.so.10) => /lib64/libcrypto.so.10
/lib64/libssl.so.10:
libk5crypto.so.3 (k5crypto_3_MIT) => /lib64/libk5crypto.so.3
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.17) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libkrb5.so.3 (krb5_3_MIT) => /lib64/libkrb5.so.3
libcrypto.so.10 (OPENSSL_1.0.1_EC) => /lib64/libcrypto.so.10
libcrypto.so.10 (libcrypto.so.10) => /lib64/libcrypto.so.10
/lib64/libcrypto.so.10:
libdl.so.2 (GLIBC_2.2.5) => /lib64/libdl.so.2
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.17) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
/lib64/libresolv.so.2:
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
/lib64/libz.so.1:
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/usr/local/lib/libbson-1.0.so.0:
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.17) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libgssapi_krb5.so.2:
libk5crypto.so.3 (k5crypto_3_MIT) => /lib64/libk5crypto.so.3
libkrb5support.so.0 (krb5support_0_MIT) => /lib64/libkrb5support.so.0
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.8) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libkrb5.so.3 (krb5_3_MIT) => /lib64/libkrb5.so.3
/lib64/libkrb5.so.3:
libresolv.so.2 (GLIBC_2.2.5) => /lib64/libresolv.so.2
libk5crypto.so.3 (k5crypto_3_MIT) => /lib64/libk5crypto.so.3
libkrb5support.so.0 (krb5support_0_MIT) => /lib64/libkrb5support.so.0
libkeyutils.so.1 (KEYUTILS_1.0) => /lib64/libkeyutils.so.1
libkeyutils.so.1 (KEYUTILS_1.5) => /lib64/libkeyutils.so.1
libkeyutils.so.1 (KEYUTILS_0.3) => /lib64/libkeyutils.so.1
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.8) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.16) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
/lib64/libcom_err.so.2:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.17) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libk5crypto.so.3:
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libkrb5support.so.0 (krb5support_0_MIT) => /lib64/libkrb5support.so.0
/lib64/libdl.so.2:
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libkrb5support.so.0:
libdl.so.2 (GLIBC_2.2.5) => /lib64/libdl.so.2
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.8) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
/lib64/libkeyutils.so.1:
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libselinux.so.1:
libdl.so.2 (GLIBC_2.2.5) => /lib64/libdl.so.2
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.8) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
/lib64/libpcre.so.1:
libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
插入操作总是成功,我可以查询我在数据库中插入的内容,但代码总是在客户端解构器中崩溃。
下面是 valgrind --tool=memcheck --track-origins=yes ./mongotest
==2787== Invalid read of size 8
==2787== at 0x5481926: mongocxx::v_noabi::client::~client() (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x54B8B81: std::_Function_handler<void (mongocxx::v_noabi::client*), mongocxx::v_noabi::pool::acquire()::{lambda(mongocxx::v_noabi::client*)#1}>::_M_invoke(std::_Any_data const&, mongocxx::v_noabi::client*) (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x41489A: std::function<void (mongocxx::v_noabi::client*)>::operator()(mongocxx::v_noabi::client*) const (std_function.h:706)
==2787== by 0x413EDA: std::unique_ptr<mongocxx::v_noabi::client, std::function<void (mongocxx::v_noabi::client*)> >::~unique_ptr() (unique_ptr.h:268)
==2787== by 0x410A3E: MongoMgr::insertSingleDoc(std::string, std::string, std::string) (MongoMgr.cpp:34)
==2787== by 0x407690: main (main.cpp:24)
==2787== Address 0x88f5b78 is 0 bytes after a block of size 8 alloc'd
==2787== at 0x4C2A203: operator new(unsigned long) (vg_replace_malloc.c:334)
==2787== by 0x54B8DA8: mongocxx::v_noabi::pool::acquire() (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x410899: MongoMgr::insertSingleDoc(std::string, std::string, std::string) (MongoMgr.cpp:34)
==2787== by 0x407690: main (main.cpp:24)
==2787==
==2787== Invalid read of size 1
==2787== at 0x5481950: mongocxx::v_noabi::client::~client() (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x54B8B81: std::_Function_handler<void (mongocxx::v_noabi::client*), mongocxx::v_noabi::pool::acquire()::{lambda(mongocxx::v_noabi::client*)#1}>::_M_invoke(std::_Any_data const&, mongocxx::v_noabi::client*) (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x41489A: std::function<void (mongocxx::v_noabi::client*)>::operator()(mongocxx::v_noabi::client*) const (std_function.h:706)
==2787== by 0x413EDA: std::unique_ptr<mongocxx::v_noabi::client, std::function<void (mongocxx::v_noabi::client*)> >::~unique_ptr() (unique_ptr.h:268)
==2787== by 0x410A3E: MongoMgr::insertSingleDoc(std::string, std::string, std::string) (MongoMgr.cpp:34)
==2787== by 0x407690: main (main.cpp:24)
==2787== Address 0x18 is not stack'd, malloc'd or (recently) free'd
==2787==
==2787==
==2787== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==2787== Access not within mapped region at address 0x18
==2787== at 0x5481950: mongocxx::v_noabi::client::~client() (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x54B8B81: std::_Function_handler<void (mongocxx::v_noabi::client*), mongocxx::v_noabi::pool::acquire()::{lambda(mongocxx::v_noabi::client*)#1}>::_M_invoke(std::_Any_data const&, mongocxx::v_noabi::client*) (in /home/dev/memo_app/dependencies/lib/libmongocxx.so._noabi)
==2787== by 0x41489A: std::function<void (mongocxx::v_noabi::client*)>::operator()(mongocxx::v_noabi::client*) const (std_function.h:706)
==2787== by 0x413EDA: std::unique_ptr<mongocxx::v_noabi::client, std::function<void (mongocxx::v_noabi::client*)> >::~unique_ptr() (unique_ptr.h:268)
==2787== by 0x410A3E: MongoMgr::insertSingleDoc(std::string, std::string, std::string) (MongoMgr.cpp:34)
==2787== by 0x407690: main (main.cpp:24)
==2787== If you believe this happened as a result of a stack
==2787== overflow in your program's main thread (unlikely but
==2787== possible), you can try to increase the size of the
==2787== main thread stack using the --main-stacksize= flag.
==2787== The main thread stack size used in this run was 8388608.
==2787==
==2787== HEAP SUMMARY:
==2787== in use at exit: 130,153 bytes in 3,535 blocks
==2787== total heap usage: 3,882 allocs, 347 frees, 286,497 bytes allocated
==2787==
==2787== LEAK SUMMARY:
==2787== definitely lost: 0 bytes in 0 blocks
==2787== indirectly lost: 0 bytes in 0 blocks
==2787== possibly lost: 640 bytes in 1 blocks
==2787== still reachable: 129,513 bytes in 3,534 blocks
==2787== of which reachable via heuristic:
==2787== stdstring : 1,384 bytes in 40 blocks
==2787== suppressed: 0 bytes in 0 blocks
==2787== Rerun with --leak-check=full to see details of leaked memory
==2787==
==2787== For counts of detected and suppressed errors, rerun with: -v
==2787== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault
非常感谢!
最好的问候
最佳答案
这一行在我看来很可疑:m_ptrPool = boost::shared_ptr<mongocxx::pool>{uri};
你能把它改成m_ptrPool = boost::make_shared<mongocxx::pool>(uri);
吗? ?
关于c++ - mongocxx 在 ~client() 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504207/
我想知道如何使用 mongocxx 3.1.3(Mongo C++ 驱动程序)执行这些命令: sh.enableSharding("YourDB") sh.shardCollection("YourD
我正在寻找 the mongocxx query exemples我不明白在这里使用 auto&& 而不是 auto& 有什么意义。 auto cursor = db["restaurants"].f
我在使用 mongodb c++ 驱动程序时遇到了一些问题。 我有以下代码并且运行良好: //bsoncxx::document::value doc-->It was defined properl
我试图在解析数据文件后将日期和时间插入到 mongocxx 中,我的实际日期时间是: 2007/12/01 00:00:00 即 2007 年 12 月 1 日午夜。我有这段代码: static bs
我正在通过 C++ API 将图像插入到 mongodb,如下所示: bsoncxx::document::value document = bsoncxx::builder::basic::m
在 mongocxx API 中,Collection.aggregate()需要一个管道对象才能运行 aggregate pipeline询问。这意味着使用 Pipeline 类构造查询。如:
司机和我有一些关于使用司机的问题。问题是我应该包含哪些头文件才能在我的项目中使用这个驱动程序?我见过这种包含文件 #include #include #include #include 和这种
我想知道 mongocxx 驱动程序 (c++) 中以下代码的等价物是什么? db.RadarPointsExl.find( { age: { $gt: 25, $lte: 50 }, {nam
我有一个查询来查找一个文档并更新我的集合中的一个文档。问题是,当我这样做时,文档被清空而不是更新。这是我的代码: auto collection = db["cities"]; bsoncxx::bu
我正在尝试在我的 C++ 示例代码中将 mongdb 与 mongocxx 驱动程序连接起来。我添加了附加包含、库和依赖项。当我构建它时,它显示以下错误。 这是完整的代码 #include "stda
我尝试使用 C++ Driver 3.1.2,代码仍然在客户端解构器中崩溃 MongoMgr.h #ifndef _MOMGODB_MANAGER_H_ #define _MOMGODB_MANAGE
Valgrind 使用 mongocxx::instance inst{} 给我一个still reachable 记录; ==3014== 16,384 bytes in 1 blocks are
以下是尝试使用带有项目查找选项的 mongo 查询的代码。 using bsoncxx::builder::stream::document; mongocxx::options::f
我目前正在尝试将一个 JSON 文件插入到我的 mongoDB 中。我已经看到这是通过过去使用 mongo::BSONObj 解决的......但这似乎不是一个选项,因为他们发布了用于 c++11 的
auto cursor = db["friend"].find({}); for (auto &&docView : cursor) { bsoncxx::builder::b
我正在尝试反向显示集合中的文档。在 shell 中,这可以通过使用以下命令来完成: db.testcollection.find().sort({$natural:-1}) 在文档中我找到了这个函数:
我正在使用以下代码查询一个集合: bsoncxx::stdx::optional query_result = collection.find_one(bsoncxx::builder::stream
我需要使用 GridFS 规范随机访问存储在 MongoDB 中的文件。看来 C++ 驱动程序 (mongocxx) 没有提供执行此操作的接口(interface)。我可以从 mongocxx::gr
我想使用 PIMPL 成语编写一个到 mongocxx 的接口(interface)。接口(interface)本身可以工作,但我对 mongocxx 内联命名空间做错了,因为编写测试不起作用。 这是
以下是我尝试使用 mongocxx 驱动程序查询 mongodb 的一段代码。 /*查找所有匹配过滤器的代码*/ mongocxx::cursor cursor = collection.find(
我是一名优秀的程序员,十分优秀!