ObjectID-Go helps to bridge the gap between the new mongo-go-driver and previous community run drivers such as mgo.
For people not migrating, this also helps cover some of the pitfalls and frustrations of mongo-go-driver's primitive package which is extremely brittle, leaks too much of the driver to the clients of the API, and can even cause unexpected panics when unmarshalling
This package follows the community run driver standard of using strings to represent objectIDs instead of [12]bytes, allowing for a much smoother development experience.
- This package automatically converts all oid.ObjectID types into primitive.ObjectIDs when marshalling or unmarshalling into bson
- no panics on JSON unmarshalling
- uses string types to avoid the driver bleeding to the API and give more control to the dev
- fixes vet errors that was rampant in the community drivers
- combines the best features of community drivers and the primitive package
- makes migrating significantly easier
go get -u github.com/qhenkart/objectid-go
or
dep ensure --add github.com/qhenkart/objectid-go
type User struct {
ID oid.ObjectID `bson:"_id" json:"id"`
}
and use the struct with json un/marshallers and the mongo-go-driver methods without a second thought
Check the godocs for additional functionality and helpers