[GODRIVER-881] ObjectID should be quoted in bsoncore.Value's String() method Created: 15/Mar/19  Updated: 28/Oct/23  Resolved: 18/Mar/19

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

Type: Bug Priority: Major - P3
Reporter: Matthew Chiaravalloti Assignee: Matthew Chiaravalloti
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In x/bsonx/bsoncore/value.go, the function func (v Value) String() string writes ObjectedIDs as {{

{"$oid":%s}

}}, but the %s should be quoted, like this: {{

{"$oid":"%s"}

}}.



 Comments   
Comment by Githook User [ 18/Mar/19 ]

Author:

{'name': 'Matthew Chiaravalloti', 'username': 'mattChiaravalloti', 'email': 'matthew.chiaravalloti@mongodb.com'}

Message: GODRIVER-881: Fix bsoncore.Value.String() ObjectID case

Change-Id: Ia70fe98ce630bec046134e34098f1fa59e97fe0d
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/c72645a64800adf5455dd9ad9cb811c0bf7d34c1

Comment by Matthew Chiaravalloti [ 15/Mar/19 ]

Update: I switched to converting from ast.Pipeline to []bson.Raw and now no longer rely on bsoncore.Value.String(). This is not longer a bug causing problems in the go driver; however, like Kris said, it is still a valid change!

Comment by Matthew Chiaravalloti [ 15/Mar/19 ]

Ooh, thank you for pointing that out. That's definitely better than the Unmarshal([]byte(Value.String())) way of doing it. Thanks!

Comment by Kristofer Brandow (Inactive) [ 15/Mar/19 ]

matthew.chiaravalloti, I think we can do this, since the output is supposed to be extended JSON, however you might want to use bson.RawValue which is a wrapper around bsoncore.Value and provides an Unmarshal method, which you should be able to use to turn it into a []bson.D.

Comment by Matthew Chiaravalloti [ 15/Mar/19 ]

It's a (probably) temporary reliance. We used to translate SQL expressions into []bson.D, but are switching to use the new mongoast ast.Pipeline type. Currently, there is a need to convert between ast.Pipeline and []bson.D, and the least amount of code to do that is to deparse the ast.Pipeline into a bsoncore.Value, and then bson.UnmarshalExtJSON that Value into a []bson.D. The Unmarshal function thats a []byte, so I use the Value.String() method to get that.

Comment by Jeffrey Yemin [ 15/Mar/19 ]

Why is BIC relying on the String value of an ObjectId like this? I though String is intended to be informational, not normative? Can BIC use the extended JSON support instead?

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