Closed jclaessens97 closed 1 year ago
Weird that it works for insert but not find.
I would guess the FeatureCollection type needs to implement MarshalBSON and UnmarshalBSON. I'm surprised the driver doesn't fallback to MarshalJSON is those aren't available.
Yeah it's really weird... It does fallback to MarshalJSON
. But if I wrap MarshalJSON
in a function like follows
func (fc FeatureCollection) MarshalBSON() ([]byte, error) {
return fc.MarshalJSON()
}
I get runtime error: invalid memory address or nil pointer dereference
And if I implement UnmarshalBSON
like follows:
func (fc FeatureCollection) UnmarshalBSON(data []byte) error {
return fc.UnmarshalJSON(data)
}
I get error decoding key routes.0.legs: invalid character 'î' looking for beginning of value
This is my first bigger project in Go, so I'm not entirely sure how I should go about this, but I can't imagine I'm the first who tries to insert a geoJSON in a mongoDB using Go? 😄 Any chance you can point me in the right direction?
Weird that it works for insert but not find.
Find decodes the data to Go values. Decode fails because the codec does not know the type to create for an orb.Geometry.
I would guess the FeatureCollection type needs to implement MarshalBSON and UnmarshalBSON.
Yes.
I'm surprised the driver doesn't fallback to MarshalJSON is those aren't available.
BSON and JSON are different data encodings. MarshalJSON returns JSON, not BSON.
I have PR to add support for BSON. Please have a look https://github.com/paulmach/orb/pull/123
Thanks @paulmach, I'll check it on friday!
merged https://github.com/paulmach/orb/pull/123 and published https://github.com/paulmach/orb/releases/tag/v0.9.0 with the change
I wanted to add a struct containing a featureCollection to mongoDB. Inserting the document isn't an issue, but as soon as I want to fetch the document it fails with the following message:
error decoding key routes.0.legs.features.0.geometry: no decoder found for orb.Geometry
.My inserted document looks like this:
Is this a bug? Or is there anything I can do differently to encode/decode
orb.Geometry
?