Tip for geoqueries and go 1.3 tip

34 views
Skip to first unread message

Karl J. Smith

unread,
Apr 9, 2014, 2:24:08 PM4/9/14
to mgo-...@googlegroups.com
I was having issues with geoqueries.

Under go 1.2.1, it worked fine.
Under go 1.3 tip, it worked fine most of the time.

Some of the time (1/20th of the time?), iter.Query returned an error like this:
geo values have to be numbers :: caused by :: { 0: 0.0007853538928210314, 1: [ -122.253685, 37.537502 ] }
The fix turned out to switch to bson.D instead of bson.M. This didn't seem to matter at all under go 1.2.1, but breaks some of the time under 1.3

e.g. switch from

              q := bson.M{
                        "where": bson.M{
                                "$nearSphere":  []float64{lng, lat},
                                "$maxDistance": distance,
                        },
                }
        
to
        q := bson.M{
                "where": bson.D{
                        {"$nearSphere", []float64{lng, lat}},
                        {"$maxDistance", distance},
                },
        }

Karl J. Smith

unread,
May 17, 2014, 1:53:59 PM5/17/14
to mgo-...@googlegroups.com
The explanation of exactly why this happens is here:

Reply all
Reply to author
Forward
0 new messages