I need get 1 rand record from a collection. I check it on robo-mongo and it work great. But in golang project using mgo.v2, It always return the same record all the time . Is there any bug with the library, or I misunderstanding?
I use "gopkg.in/mgo.v2". Here is my code:
var err error
pipe := col.Pipe([]bson.M{
{"$match": bson.M{ "ad_group_id": worker.creative.AdGroupId }},
{"$sample": bson.M{ "size": 1 }},
})
var resp []model.Coordinate
err = pipe.All(&resp)
log.Print("++++++++++++++++++++++++++++++++++++++++++++++++++: ",resp)
=>
[
{
ObjectIdHex("...") ObjectIdHex("...") ObjectIdHex("...")
{
Point [33 33]
}
t3
}
]