I am trying to create a Golang MongoDB connector that takes in a request from a client and updates/inserts the request body into a database. An example of the request body is:
{
"_id": {
"$oid": <hexOID>
},
"DateCreated": {
"$date": 1460091636474
},
"DateModified": {
"$date": 1542241349721
}
}
The current Mongo driver and BSON library I am using is the one located at github.com/globalsign/mgo/ and github.com/globalsign/mgo/bson respectively.
Whenever I try to unmarshal the above response, I get an error:
cannot parse date: "{
\"$date\": 1460091636474
}"
I've read around and saw some answers about creating a custom marshaller/unmarshaller but how would I go about doing that if it does solve this problem?
A subset of my code is as follows:
var update interface{}
errUpdate := bson.UnmarshalJSON(body, &update)
if errUpdate != nil {
fmt.Println(errUpdate)
}
dbErr = collection.Update(query, update)
I keep update as an interface since the request body that is passed constantly changes and is not well-defined.