[CXX-543] Add pointers to parent objects to mongocxx classes Created: 23/Feb/15  Updated: 23/Feb/16  Resolved: 23/Feb/16

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Jonathan Reams Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If I have a mongocxx::collection/database object, it'd be very helpful to be able to get the parent object so that you can walk from collection to database to client without having to pass lots of references around in function parameters.



 Comments   
Comment by Andrew Morrow (Inactive) [ 23/Feb/16 ]

It doesn't seem like we want to do this.

Comment by Adam Midvidy [ 23/Feb/15 ]

Users are responsible for ensuring that a collection/database lifetime is a subset of its parent client.

Collections, however, do not depend on their parent databases, so a method for a collection to hand back a database object would be problematic.

EDIT:

And yes, users manually managing lifetime of driver objects was a deliberate decision. I wasn't really part of the discussion, but the rest of the team was strongly opposed to having an internal graph of smart pointers.

Comment by Jonathan Reams [ 23/Feb/15 ]

Is having users manually manage lifetime of the driver objects an explicit goal? Can you even have a working collection object without a valid database/client object?

Comment by Adam Midvidy [ 23/Feb/15 ]

On further thought, the issue here is that we don't manage lifetimes of the driver's objects. I think we would need to have db hold a shared_ptr to client, and collection hold a shared_ptr to client and db for this to work without letting users shoot themselves in the foot.

Requiring users pass around objects explicitly, though inconvenient and verbose, ensures that they manage the lifetime of driver objects manually.

Generated at Wed Feb 07 21:59:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.