Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-393

byte stream parsed with extjson and encoded to a document results in extjson looking objects

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: JSON & ExtJSON
    • None

      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.

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            davidboon@invisionapp.com David Boon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: