[CDRIVER-3093] Include inserted _Ids in insert_one() and insert() results Created: 23/Apr/19  Updated: 07/Mar/23

Status: Backlog
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Stennie Steneker (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 2
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to PHPLIB-428 Report successfully inserted IDs afte... Backlog
Epic Link: Improve Developer Experience
Quarter: FY24Q3
Case:

 Description   

As per http://mongoc.org/libmongoc/current/mongoc_collection_insert_one.html and http://mongoc.org/libmongoc/current/mongoc_collection_insert.html, there is currently no option to return the generated _id(s):

If no _id element is found in document, then a bson_oid_t will be generated locally and added to the document. If you must know the inserted document’s _id, generate it in your code and include it in the document. The _id you generate can be a bson_oid_t or any other non-array BSON type.

Although providing the inserted id(s) is not required according to the MongoDB CRUD spec, it would be useful to expose this in the C driver to assist downstream drivers such as mongolite that use libmongoc.



 Comments   
Comment by Kevin Albertson [ 10/Jun/19 ]

Hi stennie, is there another issue to link to?

Comment by Jeremy Mikola [ 14/May/19 ]

stennie: Still waiting for an issue to cross-reference if you have it handy.


On a separate note, this issue came up in relation to PHPLIB-428. While implementing the retryable writes test runner, I realized that it's quite difficult to assert inserted IDs from incomplete write results returned after a bulk write error. As described in that issue, I believe it's possible to calculate the map of inserted IDs that we expect to have completed successfully but it's a fair bit of work.

Comment by Jeremy Mikola [ 23/Apr/19 ]

Is there another issue to cross-reference with this request for added context? This isn't terribly difficult to implement in a wrapping driver (e.g. PHP, Swift), as it's a matter of fetching the _id field from the document(s). Does mongolite provide no abstraction around libmongoc's own result objects?

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