The similar interface is named bson.Getter
:
It can look similar to this:
func (point *Point) GetBSON() (interface{}, error) {
return bson.D{{"x", point.X.String()}, {"y", point.Y.String()}}, nil
}
And there's also the counterpart interface in the setter side, if you're interested:
For using it, note that the bson.Raw
type provided as a parameter has an Unmarshal
method, so you could have a type similar to:
type dbPoint struct {
X string
Y string
}
and unmarshal it conveniently:
var dbp dbPoint
err := raw.Unmarshal(&dbp)
and then use the dbp.X
and dbp.Y
strings to put the big ints back into the real (point *Point)
being unmarshalled.