If you look at the documentation of the mgo
package, you will see the structs there are annotated with `bson:"fieldName`
not `json:"fieldName"`
. You can see an example here
The reason for this is that mongo uses the bson
serialization format instead of json
to send the structures over the wire. bson
is very similar to json
in what it can store, but it is a binary format, and is optimized for use in storage systems like a database.
So update your struct to look like so:
type Event struct {
Id string `bson:"id"`
CreationDate time.Time `bson:"creationTime"`
CreatorId string `bson:"creatorId"`
Place string `bson:"place"`
ActivityId string `bson:"activityId"`
Time time.Time `bson:"time"`
Lang string `bson:"lang"`
}
You can actually use both json
and bson
tags at the same time.
type Event struct {
Id string `json:"id" bson:"id"`
CreationDate time.Time `json:"creationTime" bson:"creationTime"`
CreatorId string `json:"creatorId" bson:"creatorId"`
Place string `json:"place" bson:"place"`
ActivityId string `json:"activityId" bson:"activityId"`
Time time.Time `json:"time" bson:"time"`
Lang string `json:"lang" bson:"lang"`
}