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

Is it safe to use collection after connection (from which it was created) is destroyed?

    • Type: Icon: Task Task
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      The mongocxx driver API is designed such that you get a connection object from the pool and then you get a database from the connection. Any operations then happen over that connection I assume? So my question is do I need to keep the connection object alive while I use database/collection objects? e.g.

      CollectionWrapper::CollectionWrapper {
       connection = pool.acquire();
       db = connection.database("my_database");
       m_collection = db.collection("my_collection);
      } // << connection object destroyed here but member variable m_collection is still alive
      

      Or does the fact that I am keeping the collection alive is enough to ensure the connection is not returned to the pool?

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            puya@motionmetrics.com Puya Daravi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: