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

empty bson.RawValue marshal unmarshal behavior are inconsistent. unmarshal error

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.12.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      when i read a mongo struct from mongodb, then process some filed, marshal to bytes, then store to cache.

      when  other scenes, get bytes from cache, then unmarshal it , it is not work.

      like this: 

      unmarshal error document is invalid, end byte is at 28, but null byte found at 21

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      the latest  version  v1.12.0 still has the same bug

      How to Reproduce

      type P struct

      {   Name string `bson:"name,omitempty"`   Likes bson.RawValue `bson:"likes,omitempty"` }

      func TestMismatch(t *testing.T)

      {   bytes, err := bson.Marshal(&P\{Name: "lilei"}

      )
        if err != nil

      {       t.Fatalf("marshal error %s", err)   }

        var p P
        err = bson.Unmarshal(bytes, &p)
        if err != nil

      {      t.Fatalf("unmarshal error %s", err)   }

      }

      Additional Background

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            1124210681@qq.com mongo mongo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: