I have unknown json structure data stored in mongodb. They have the fields to present the unix time like this:
"date": 1424803567,
I am using mgo to load them to the bson.M.
var result bson.M
iter := c.Find(q).Iter()
for iter.Next(&result) {
Those unix time fields have turned to the fload64 instead of the int.
"date": 1.424728798e+09,
So, how to prevent that happens in the case above? thanks!
Mgo does not unmarshal an integer to a float unless destination value is explicitly typed as a float by the application. Mgo is returning a float value here because the value stored in the database is a float.
You can unmarshal the float value to an integer by specifying the type using a struct:
var result struct {
Date int64 `bson:"date"`
}
for iter.Next(&result) {
...
}