RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

mongodb geospatial request

Thank you very much Katya - it's called "test" and is now shared.

  1. run app and click "within miles" on footer

  2. click update

    You'll notice that e.g. the first doc returned has a latitude and longitude that is far further away from my target location (the one sent to the where param) than 1 mile

    I've sent to support my database credentials.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

mongodb geospatial request

Hi Robert,

You seem to do everything correctly.

I would recommend that you check this thread and contact https://support.mongolab.com/home

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

mongodb geospatial request

Thank you Katya.

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

mongodb geospatial request

UPDATE: Just wanted to report back that MongoDB support said I had set my index for the location field incorrectly - I was using the 2d version when I needed to use the 2dsphere version. All now works perfectly - and between the great support from appery and the great support from mongodb, life is good. Thanks Katya.

Shawn Johnson
Posts: 0
Joined: Wed Jan 15, 2014 4:17 pm

mongodb geospatial request

Robert,

Do you mind sharing a screen shot, or a example of the correct solution to the issue, It would be helpful to myself and possible others

Thanks
-Shawn

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

mongodb geospatial request

Here's what I did Shawn - hope this helps.

  1. Saved as a CSV file an Excel sheet with "latitude" and "longitude" colums.

  2. Imported (uploaded) it to MongoDB using MongoImport.exe

  3. In MongoDB shell, created a new indexed field - an object called "loc" which combines "latitude" and "longitude" using this code:

    yourdbname.yourcollectionname.find({"loc": {"$exists": 0}}).forEach(function (doc) {
    yourdbname.yourcollectionname.update({"id": doc['id']},{"$set": { "loc": [doc['longitude'], doc['latitude']]}});
    })

    yourdbname.yourcollectionname.ensureIndex({"loc":"2dsphere"})

  4. In appery.io, mapped the parameter "q" to local storage variable using this code:

    var t1 = {

    "loc":

    {"$near":
    {"type":"Point","coordinates":[target longitude -xx.xxxx ,target latitude xx.xxxxxx], "$maxDistance": target distance in miles xx}
    }

    };

    var t2 = JSON.stringify(t1);

    localStorage.setItem("local storage var name",t2);

    Note: MongoDB may have a bug (they are looking into it) where docs are returned which exceed the desired radius. But they are returned in ascending order of miles away from target location - and so you can set up a limiting request parameter "l" to restrict the number of returned docs.

Shawn Johnson
Posts: 0
Joined: Wed Jan 15, 2014 4:17 pm

mongodb geospatial request

Thanks Robert

Return to “Issues”