I am using Go language and MongoDB with mgo.v2
driver and I have struct like
type MarkModel struct {
ID bson.ObjectId `json: "_id,omitempty" bson: "_id,omitempty"`
Name string `json: "name" bson: "name"`
Sum int `json: "sum" bson: "sum"`
Delta int `json: "delta" bson: "delta"`
}
I need to find all where is Sum + Delta < 1000
for example. At the moment I load all and then in Go code I filter but I would like to filter on query level.
How to make that query ?
At the moment I return all with
marks := []MarkModel{}
c_marks := session.DB(database).C(marksCollection)
err := c_marks.Find(bson.M{}).All(&marks)
if err != nil {
panic(err)
}
and here I filter in Go code in for loop but it is not optimal ( it is bad solution ).