[GODRIVER-393] byte stream parsed with extjson and encoded to a document results in extjson looking objects Created: 30/Apr/18  Updated: 03/Oct/19  Resolved: 03/Oct/19

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Boon Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

A byte stream parsed with extjson and encoded to a document results in a collection entry that looks like:

 

 db.test_1.find({});
{ "_id" : ObjectId("5ae73f81c9fd3a4da04a5593"), "id" : NumberLong(13679126), "a1" : [ { "a1_1" : [ { "id" : NumberLong(32323482) } ] }, { "a1_2" : [ { "id" : NumberLong(32323484) } ] } ], "name" : "name test" } 

 

 

The relevant code block that produced that entry is:

 

 
{code:java}
  f, err := os.Open("doc.json")
  if err != nil {
    panic(err)
  }  b, err := ioutil.ReadAll(f)
  if err != nil {
    panic(err)
  }
  builder, err := extjson.ParseObjectToBuilder(string(b))
  if err != nil {
    panic(err)
  }  buf := make([]byte, builder.RequiredBytes())
  _, err = builder.WriteDocument(buf)
  d, err := bson.NewDocumentEncoder().EncodeDocument(buf)  fmt.Printf("decoded document:\n")
  
  _id := objectid.New()
  d.Set(bson.EC.ObjectID("_id", _id))
  filter := bson.NewDocument(bson.EC.Int32("id", 13679126))  client, err := mongo.NewClient("localhost:27017")
  if err != nil {
    panic(err)
  }
  db := client.Database("test")
  coll := db.Collection("test_1")
  coll.DeleteOne(context.Background(), filter)
  res, err := coll.InsertOne(context.Background(), d)
  if err != nil {
    panic(err)
  }
  

 

I would expect the resulting entry to be free of NumberLong. Is there a way to control how the document is stored, why does the document get created with NumberLong? I have created documents programmatically without using the extjson package and those appear fine.

 



 Comments   
Comment by Esha Bhargava [ 03/Oct/19 ]

davidboon@invisionapp.com The extjson library has been replaced by bson.UnmarshalExtJson. Please update your code and let us know if the problem still exists.

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