[GODRIVER-1846] Have bsoncore.Array marshal into an array type instead of an embedded document Created: 21/Jan/21  Updated: 28/Oct/23  Resolved: 10/Feb/21

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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.



 Comments   
Comment by Kevin Albertson [ 11/Feb/21 ]

Cherry-picked onto release/1.5 with https://github.com/mongodb/mongo-go-driver/commit/fda5d252856ea9eb101422b00f9756f2e11ab45b

Comment by Githook User [ 10/Feb/21 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-1846 Add bsoncore.Array type with new codec (#571)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/0f54b6155e6fa4aab38ee12979c7aba60f8dbdf7

Comment by Benji Rewis (Inactive) [ 01/Feb/21 ]

https://github.com/mongodb/mongo-go-driver/pull/571

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