[GODRIVER-1121] Error when unmarshaling a BSON document if the document has unknown fields Created: 10/Jun/19  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Eric Bajumpaa Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: jeff+
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by GODRIVER-3044 Error when unmarshaling a BSON docume... Closed
Backwards Compatibility: Fully Compatible

 Description   

This is in reference to the comment here.

The struct decoder should have the ability to report non-existent field. Go's json decoder has support for this documented here. I've played around this a bit, and the quickest way to implement this would be potentially exposing a similar function in the RegistryBuilder`. All decoders have a reference to the registry through DocodeContext.

Definition of done

  • Add a configuration that causes decoding to return an error if there are fields in the decoded BSON document that don't match fields in the decode destination struct. Note that this only makes sense when the destination is a struct.
  • Add the ability to configure that unmarshal behavior on a MongoDB Client using BSONOptions.

Pitfalls

  • Adds additional configuration to the bson.Decoder type, which already has a lot of configurable behaviors.


 Comments   
Comment by Eric Bajumpaa [ 10/Jun/19 ]

I've put together a PR with the solution I envisioned mongodb/mongo-go-driver#163.

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