[GODRIVER-1783] omitempty doesnt work on primitive.Decimal128 Created: 06/Nov/20  Updated: 28/Oct/23  Resolved: 11/Nov/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 1.4.2
Fix Version/s: 1.4.4

Type: Bug Priority: Major - P3
Reporter: Cam Graff Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

type Something struct {
	Field primitive.Decimal128 `bson:"field,omitempty"`
}
 
func main() {
        // Connect to mongo instance
        // ... 
 
	something := Something{}
	collection := client.Database("invoice").Collection("something")
	_, err = collection.InsertOne(context.Background(), something)
	if err != nil {
		log.Fatal(err)
	}
 
}

After running the above, a record is created with the primitive.Decimal128 field while it should be omitted.

{
    "field": {
        "$numberDecimal": "0E-6176"
    }
}



 Comments   
Comment by Githook User [ 11/Nov/20 ]

Author:

{'name': 'Isabella Siu', 'email': 'isabella.siu@mongodb.com', 'username': 'iwysiu'}

Message: GODRIVER-1783 add tests for IsZero for ObjectID and Decimal128 (#533)
Branch: release/1.4
https://github.com/mongodb/mongo-go-driver/commit/b15c218403d30e08b7566a6c541e7d00fd16e980

Comment by Githook User [ 11/Nov/20 ]

Author:

{'name': 'camgraff', 'email': '46980357+camgraff@users.noreply.github.com', 'username': 'camgraff'}

Message: GODRIVER-1783 make primitive.Decimal128 implement Zeroer (#532)
Branch: release/1.4
https://github.com/mongodb/mongo-go-driver/commit/6cfa339de6db8776035d40fae8df7fdf7a2c3fe8

Comment by Githook User [ 11/Nov/20 ]

Author:

{'name': 'Isabella Siu', 'email': 'isabella.siu@mongodb.com', 'username': 'iwysiu'}

Message: GODRIVER-1783 add tests for IsZero for ObjectID and Decimal128 (#533)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/be40d50a6c1d836bb1e4a1fcc8cae09f24d20576

Comment by Githook User [ 10/Nov/20 ]

Author:

{'name': 'camgraff', 'email': '46980357+camgraff@users.noreply.github.com', 'username': 'camgraff'}

Message: GODRIVER-1783 make primitive.Decimal128 implement Zeroer (#532)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/6ecacaa391c868df32270b906e3b9968232a1ae4

Comment by Cam Graff [ 06/Nov/20 ]

I've opened a PR to fix this https://github.com/mongodb/mongo-go-driver/pull/532

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