I'm new in Go and MongoDB. And I faced with a following case:
I have following document:
{
"_id": "568adf31945dbe55e3189f6a"
"test1": 5
"test2": 10
"status": "in progress"
}
And I need to increment test1 field while it is less than test2.
If I want to compare field with a static value I can use following code:
change := mgo.Change{Update: bson.M{"$inc": bson.M{"test1": 1}},}
myModel := models.MyModel{}
info, err := db.Find(
bson.M{"_id" : bson.ObjectIdHex("568adf31945dbe55e3189f6a"),
"test1": bson.M{ "$lt": 10 }}).Apply(change, &myModel)
But how can I compare test1 with test2 field in the find function? (I want to have atomic find without additional requests to the database)
Thank you.