Detailed steps to reproduce the problem?
Include full traceback, if possible
Definition of done: what must be done to consider the task complete?
- EncodeContext for struct codec needs to pass omitEmpty
- Add a regression test
The exact Go version used, with patch level:
$ go version go1.26.2 linux/amd64
The exact version of the Go driver used:
$ go list -m go.mongodb.org/mongo-driver
Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.
The operating system and version (e.g. Windows 7, OSX 10.8, ...)
Security Vulnerabilities
If you've identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here
Up to now, I've elected to use the "omitempty": true in the bson options, saves me adding the tag attrbute to my structs.
However, I've noticed it's not working when I have a nested struct.
e.g.
type Filter[T any] Struct
{ LessThan *T `bson:"$lt"` LessThanOrEqual *T `bson:"$lte"` }type Apple Struct
{ Price *Filter[float64] `bson:"price"` }If I have Apple.Price as nil, it's ommited, but when it's present, the nested Filter struct has all Values, where they are present or not.
Surely the client options, BSON, omitempty should extend to these too?