[GODRIVER-468] adding _id to a *bson.Document mutates the document. Created: 18/Jun/18  Updated: 28/Oct/23  Resolved: 23/Oct/18

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 0.0.7
Fix Version/s: 0.0.18

Type: Bug Priority: Major - P3
Reporter: Sam Kleinman (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

While the driver should add an ID in these cases, I don't think that its correct that the driver should mutate the document you have a pointer to.



 Comments   
Comment by Jeffrey Yemin [ 23/Oct/18 ]

This has been addressed by the bson refactoring work.  Now:

 

 document := bson.NewDocument()
 result, err := coll.InsertOne(context.Background(), document)
 println("_id nil?: ", document.Lookup("_id") == nil)

prints:

_id nil?: true

Generated at Thu Feb 08 08:34:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.