-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
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.