Skip to content

Mongo/BSON: no decoder found for orb.Geometry #122

@jclaessens97

Description

@jclaessens97

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:
image

type SimulationInput struct {
	Status    SimulationStatus `json:"status" default:"RUNNING"`
	CreatedAt time.Time        `json:"createdAt" bson:"createdAt"`

	Ship                 Ship                 `json:"ship"`
	Routes               []Route              `json:"routes"`
}

type Route struct {
	Name                string                     `json:"name"`
	TwoWay              bool                       `json:"twoWay"`
	Legs                *geojson.FeatureCollection `json:"legs"`
}

func (s *MongoStore) SaveSimulationInput(input *data.SimulationInput) interface{} {
	result, err := s.inputCollection.InsertOne(context.Background(), input)
	if err != nil {
		s.logger.Error(err)
	}
	return result.InsertedID
}

func (s *MongoStore) GetSimulationInput(id string) (*data.SimulationInput, error) {
	objectId, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return nil, err
	}
	filterQuery := map[string]interface{}{
		"_id": objectId,
	}

	var simulationInput *data.SimulationInput
	if err := s.inputCollection.FindOne(context.Background(), filterQuery).Decode(&simulationInput); err != nil {
		return nil, err
	}
	return simulationInput, nil
}

Is this a bug? Or is there anything I can do differently to encode/decode orb.Geometry?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions