globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 232 forks source link

add support for "objectid" bson flag string and string pointer #357

Closed ilius closed 5 years ago

ilius commented 5 years ago

This allows us to use the type string instead of ObjectId in struct fields, so that our struct types are not bson-specific (may want to have xml tags or sql db tags in the same struct for example)

Example:

type EventModel struct {
    EventId   string    `bson:"_id,objectid" json:"eventId"`
}
ilius commented 5 years ago

Related: https://github.com/globalsign/mgo/issues/98

ilius commented 5 years ago

I changed "hex" tag to "objectid"