0

I wrote something like:

bsoncxx::document::value filter_document =  document{}
      << "_id" << bsoncxx::oid  { strJobID }
      << finalize;
auto retVal = collTasks.find_one(
      filter_document, mongocxx::options::find {});

Result:

../src/CMongo.cpp:371:73: 
error: cannot bind 
‘bsoncxx::v_noabi::document::value’ lvalue to
‘bsoncxx::v_noabi::document::value&&’
       auto retVal = collTasks.find_one(filter_document, MyFindOptions);

It's looking pretty much like the example. and the type of the argument is viwe_or_value...

Cutton Eye
  • 3,207
  • 3
  • 20
  • 39

1 Answers1

0

There are owning and not owning type to represent the data.

  • value is the owning type

  • view the non owning type

If a owning type leves its scope {...} than it is destroying the underlying databuffer. A view generatrated from a value can't destroy the databuffer. But it depents on it. The view is referencing on the databuffer of the value. so if the view is valid, but value not, this leads somitimes into a SIGSEG a segmentation fault. Because you're trieng to acces data which are not existing anymore.

You don't want your fint_one() function to distroy your generated ID. This why this function accepts not a value. Btw: Those && are moving-Operators. A Object is not copied, it is cut and paste. The source doesn't have this afterwards.

So try following, it should work ;).

docJobReturned = collTasks.find_one( filter_document.view(), mongocxx::options::find {});

Cutton Eye
  • 3,207
  • 3
  • 20
  • 39