Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1846

Have bsoncore.Array marshal into an array type instead of an embedded document

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Currently bsoncore.Array marshals into an embedded document instead of an array.

      An example:

      type CursorDocs struct {
      	FirstBatch []bson.D `bson:"firstBatch"`
      	Id         int64    `bson:"id"`
      	Ns         string   `bson:"ns"`
      }
      
      type Cursor struct {
      	FirstBatch bsoncore.Array `bson:"firstBatch"`
      	Id         int64          `bson:"id"`
      	Ns         string         `bson:"ns"`
      }
      

      Marshaling CursorDocs to BSON, then unmarshaling it back to Cursor, and marshaling it to BSON again results in "firstBatch" being BSON type 03 embedded document instead of the expected 04.

      This is due to bsoncore.Array being a type alias of bsoncore.Document. One suggestion is to change the type alias to be type Array Document and having a separate codec for the Array type.

            Assignee:
            benji.rewis@mongodb.com Benji Rewis (Inactive)
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: