how to resolve segmentation fault in mongo-cxx-driver's bsoncxx::to_json

30 Views Asked by At

I am using mongo-cxx-driver r3.9.0 version. simple code of creating a document and logging the document using bsoncxx::to_json is throwing segmentation fault.

stacktrace:

#0  0x00007f6108ce27d8 in bson_get_data () from /usr/local/lib64/libbson-1.0.so.0
#1  0x00007f6108ce3af0 in bson_as_json_with_opts () from /usr/local/lib64/libbson-1.0.so.0
#2  0x00007f6108ce3d32 in bson_as_json () from /usr/local/lib64/libbson-1.0.so.0
#3  0x00007f610bb3dbdf in bsoncxx::v_noabi::(anonymous namespace)::to_json_helper(bsoncxx::v_noabi::document::view, char* (*)(_bson_t const*, unsigned long*)) ()
   from /usr/local/lib64/libbsoncxx.so._noabi
#4  0x00007f610bb3dcb4 in bsoncxx::v_noabi::to_json[abi:cxx11](bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::ExtendedJsonMode) () from /usr/local/lib64/libbsoncxx.so._noabi

query is created using following lines.

    namespace bbs = bsoncxx::builder::stream;
    namespace bd = bsoncxx::document;
    using bsoncxx::builder::basic::kvp;
    using bsoncxx::builder::basic::make_array;
    using bsoncxx::builder::basic::make_document;
    using bbs::open_document;
    using bbs::close_document;
    using bbs::finalize;

    bbs::document eq_builder = bbs::document{};
    eq_builder << kUpdatedAtField << last_read_timestamp_
               << kIdField << open_document << "$gt" << last_query_id_
               << close_document << finalize;
    bbs::document gt_builder = bbs::document{};
    gt_builder << kUpdatedAtField << open_document << "$gt"
               << last_read_timestamp_
               << close_document
               << finalize;
    bd::view query = make_document(kvp("$or", make_array(eq_builder.view(), gt_builder.view())));
    LOG(INFO) << "query generated " << bsoncxx::to_json(query);

the last line, where I try to log is throwing segmentation fault.

How can I resolve this? Not sure if I am doing anything wrong while compiling the document.

0

There are 0 best solutions below