Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-439

[C++11 Driver] Make lifetime of BSONObj more explicit to the user

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.1.0
    • Affects Version/s: None
    • Component/s: API
    • None

      Hello,

      When you call the next() function on a cursor, in the 26compat driver, it gives you back a BSONObj by value, however its lifetime is driven by some internal mechanism inside the cursor object.

      We have been bitten by this and quickly fixed it by explicitely calling the copy() method if our BSONObj outlives the next call to next().

      We do understand that from a performance point of view, and given that it was directly in the server before, that this behavior of no-copy is beneficial.

      However, in a brand new driver (such as the one you seem to be creating on master branch) it would be very nice to have better visibility on the lifetime on the object just by looking at what return the functions.
      We think this is an important API design for a driver, especially now that C++11 has unique_ptr/shared_ptr or w/e type of lifetime mechanism you would need.

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            antoine.hom@amadeus.com Antoine Hom
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: