Im really new using go, mgo and gin gonic ...Ive been creating a mini app and I have a problem inserting a new register in mongoDB using mgo. My error says:
"PANIC: error parsing element 0 of field documents :: caused by ::wrong type for '0' field, expected object, found 0: [ { date: new Date(1441051152939), from: "11", to: "12", office: "2", client_id: "1368465545" } ]_"
My struct is the next one:
type Reservation struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"_id"`
Date time.Time `bson:"date" json:"date"`
From string `bson:"from" json:"from"`
To string `json:"to"`
Office string `json:"office"`
Client_id string `json:"client_id"` }
And Im trying to insert it as follows using gin-gonic and mgo:
func addReservation(c *gin.Context) {
x := session.DB("projXXXX").C("reservation")
var reservations []Reservation
c.Bind(&reservations)>
err := x.Insert(&reservations)
if err != nil {
panic(err)
}
c.String(200,"whatever")
}
My collection in mongoDB is like this:
{
"_id" : ObjectId("55ba2e611cb87b9a6d75e94b"),
"date" : ISODate("2015-10-22T00:00:00.000Z"),
"from" : "9",
"to" : "10",
"office" : "4",
"client_id" : "1123456469797"
}
Thanks a lot for your help