[GODRIVER-424] Use ExtendedJSON when stringifying bson.Reader, bson.Document, and bson.Array types. Created: 23/May/18  Updated: 24/Jul/20  Resolved: 24/Jul/20

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

Type: Improvement Priority: Trivial - P5
Reporter: Kristofer Brandow (Inactive) Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We currently use a custom format when stringifying either a bson.Reader, a bson.Document, or a bson.Array. Since we merged the extjson package into the bson package in GODRIVER-328, we can use extended JSON directly. Update the bson.Reader.String, bson.Document.String, and bson.Array.String methods to use extended JSON when printing. Ensure the calls to ToExtJSON set canonical to true.

For the bson.Element type use the extended JSON package to print the element out as a single element document.

Move the current implementation of bson.Document.String, bson.Array.String, and bson.Reader.String to a method called "DebugString".



 Comments   
Comment by Jeffrey Yemin [ 29/Nov/18 ]

PR: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/432862

Comment by Slava Bobik [ 25/Sep/18 ]

Hi, I want to create pull request to resolve this issue, but I have a question about implementation: 

Could you please explain what does it mean "For the bson.Element type use the extended JSON package to print the element out as a single element document"

For e.g 

doc := NewDocument(EC.String("key", "value"))
str := doc.ToExtJSON(true)

I've got the result 

{"key":"value"}

is it expected result? or I should get equivalent result, when I call String() method: 

bson.Document{bson.Element{[string]"key": "value"}}

 

 

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