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

How to make a decodable costum object id

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.0
    • BSON
    • None
    • go1.12 linux/amd64

    Description

      Is there a way to make ObjectIDs with own methods that can be decoded from a BSON?
      I made me a simple custom ObjectID with a valid function:

      package primitive
       
      import (
      	primitive "go.mongodb.org/mongo-driver/bson/primitive"
      )
       
      type ObjectID struct {
      	primitive.ObjectID
      }
       
      func (o ObjectID) Validate() error {
      	return nil
      }
      

      But when I use that type instead of the original in a struct and try to decode a BSON I get the following error message:

      cannot decode objectID into a primitive.ObjectID
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            karltga Karl Wolffgang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: