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

Struct with bson tag _id inserts a byte array instead of objectId

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.0.3
    • Affects Version/s: None
    • Component/s: BSON
    • None

      When having a struct like this:

      type TestStruct struct {
              ID   objectid.ObjectID `bson:"_id"`
      	Desc string            `bson:"desc"`
      }
      
      func Create() {
             t := TestStruct{
                    Desc: "Testing 1234"
             }
      
             .....InsertOne(context.Background(), t, nil)
      }
      

      This creates a byte[12] (Binary) value in the database instead of an objectID. When removing the `bson: "_id"` tag. It automatically creates a correct objectID. But then there is no bson mapping to the ID field in the struct.

            Assignee:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Reporter:
            adlecluse Ad
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: