Client BSONOptions, omitEmpty not working on nested struct

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      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?

            Assignee:
            Unassigned
            Reporter:
            Neil Duffy (EXT)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: