Hi I am pretty new to mongodb and I am trying to get example code that comes with a book to work against mongodb. I did a local installation on windows and it seems that the server comes up fine. The default port is there as expected. My golang executable which does a db connect at the outset works fine and says connecting to the database. However when I offer it a json payload derived from the code in the book it gives me a json parsing error on the location key “3” in the following json:
{
// "id": 4,
"name":"opera aida",
"startdate":768346784368,
"enddate":43988943,
"duration":120,
"location":{
"id":3,
"name":"West street Opera House",
"address":"11 west street , AZ 73646",
"country":"U.S.A",
"opentime":7,
"closetime":20,
"Hall":{
"name":"Cesar Hall",
"location":"second floor, room 2210",
"capacity":10
}
}
}
The golang main struct is event which is as follows:
type Event struct {
ID bson.ObjectId `bson:"_id"`
Name string
Duration int
StartDate int64
EndDate int64
Location Location
}
And the included Location is as follows:
type Location struct {
ID bson.ObjectId `bson:"_id"`
Name string
Address string
Country string
OpenTime int
CloseTime int
Halls []Hall
}
The parsing looks as follows:
event := persistence.Event{}
err := json.NewDecoder(r.Body).Decode(&event)
if nil != err {
w.WriteHeader(500)
fmt.Fprintf(w, `{"error": "error occured while decoding event data %s"}`, err)
return
}
And postman gives me the following error message:
{“error”: “error occured while decoding event data invalid ObjectId in JSON: 3”}
If I decomment the key (4) in event in the json above I get the same error message type
Anyone any ideas on how to tackle this ?
Thanks
Peter Geerts