0

I have the following query:

db.getCollection('spawnlocations').find({
    'location': {
        '$geoWithin': {
            '$center': [[-73.94075, 40.789138], 5000]
        }
    }, 
    "expirationtimems": { "$gte": 1234567890 }, 
    "_id": { "$gte": "2a920240836c40d8b374203a798a27fa.16" }
}).sort({"_id":1}).limit(50)

I am trying to convert the query to mgo using bson.M but I'm having a hard time with the array part of it.

I thought this would work, but of course it doesn't

    q = bson.M{
        "location": bson.M{
            "$geoWithin": bson.M{
                "$center": [
                    j.Location.Coordinates,
                    5000
                ],
            },
        },
        "expirationtimems": bson.M{
            "$gte": time.Now().Unix() * 1000,
        },
        "_id": bson.M{
            "$gt": p,
        },
    }
chridam
  • 100,957
  • 23
  • 236
  • 235
Valerio Santinelli
  • 1,592
  • 2
  • 27
  • 45

1 Answers1

4

Use this:

"$center": []interface{}{j.Location.Coordinates, 5000}

This line is probably an error:

 time.Now().Unix() * 1000

Did you want + 1000?

Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242