I'm developing a RESTful API in go with the mgo driver for the MongoDB.
The problem is that I'm trying to fetch documents by a field of type int and no results is returned.
For example I have this document:
{
"_id" : ObjectId("5797833e9de6f8c5615a20f9"),
"id" : "28743915-9be0-427d-980d-5009bfe1b13a",
"name" : "Hunter",
"rating" : 2.9,
"downloads" : 5040
}
And when trying to fetch this document with:
conn.Session.
DB("face").
C("papers").
Find(bson.M{"rating": 2.9}).
All(&papers) // papers is an instance of a slice struct.
It will not return any documents but doing the same in a mongo shell returns documents, for example:
db.papers.find({"rating": 2.9})
But doing this in the mongo shell won't return any documents:
db.papers.find({"rating": "2.9"})
So I think that the problem might be that when bson.M is being serialized it might convert the value to a string, because that bson.M is a map[string]interface{}
This is how the Paper struct looks like
type Paper struct {
ID string `json:"id,omitempty" bson:"id"`
Name string `json:"name,omitempty" bson:"name"`
Rating float64 `json:"rating" bson:"rating"`
Downloads int `json:"downloads" bson:"downloads"`
}