int CMongo::FindOne(std::string strJSONFind, std::string strJSONOrderBy, core::v1::optional<bsoncxx::v_noabi::document::value> &docReturn ){
int iErr = 0;
mongocxx::options::find MyFindOptions{};
MyFindOptions.sort(bsoncxx::from_json(strJSONOrderBy).view());
// core::v1::optional<bsoncxx::v_noabi::document::value> XXX;
try{
//docReturn = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // SEGFAULT
// XXX = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
// auto i = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
auto i = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
class CMongo {
public:
CMongo();
int FindOne(
std::string strJSONFind,
std::string strJSONOrderBy,
core::v1::optional<bsoncxx::v_noabi::document::value> &docReturn );
virtual ~CMongo();
private:
mongocxx::client conn; // connection to database
class mongocxx::v_noabi::collection collJobs;
};
CMongo::CMongo() {
// TODO Put this in every init functions withe a question of existence
mongocxx::client conn(mongocxx::uri("Mongo credentiales" ));
collJobs = conn["Database"]["collection"];
}
CMongo MyMongo;
core::v1::optional<bsoncxx::v_noabi::document::value> ReturnVal;
MyMongo.FindOne("{\"started\":false}","{\"date\":1,\"priority\":1}",ReturnVal);
Calling in this assambly the funcion find_one() is throwing a segfault. I don't know why.
It looks like an obvious misstake...
Member function:
int CMongo::FindOne(std::string strJSONFind, std::string strJSONOrderBy, core::v1::optional<bsoncxx::v_noabi::document::value> &docReturn ){
int iErr = 0;
mongocxx::options::find MyFindOptions{};
MyFindOptions.sort(bsoncxx::from_json(strJSONOrderBy).view());
// core::v1::optional<bsoncxx::v_noabi::document::value> XXX;
try{
//docReturn = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // SEGFAULT
// XXX = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
// auto i = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
auto i = collJobs.find_one(bsoncxx::from_json(strJSONFind).view(),MyFindOptions); // segfault
Class header:
class CMongo {
public:
CMongo();
int FindOne(
std::string strJSONFind,
std::string strJSONOrderBy,
core::v1::optional<bsoncxx::v_noabi::document::value> &docReturn );
virtual ~CMongo();
private:
mongocxx::client conn; // connection to database
class mongocxx::v_noabi::collection collJobs;
};
Class Constructor:
CMongo::CMongo() {
// TODO Put this in every init functions withe a question of existence
mongocxx::client conn(mongocxx::uri("Mongo credentiales" ));
collJobs = conn["Database"]["collection"];
}
Note: this isn't your problem, but you shouldn't need the .view calls above.