Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Say I am looking for the nearest location that contain the word seaworld.

I don't want mongodb to "scan" an area too wide.

So I want to limit it

I send

db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106, -6], "$within" : { "$box" : [[105, -7], [107, -5]] } }, "indexContents" : "seaworld" }, { "LongitudeLatitude" : 1 }).limit(50);

And this is the result:

/* 0 */
{
  "_id" : "popeye-seaworld-ancol__-6.13_106.84",
  "LongitudeLatitude" : {
    "Longitude" : 106.843315,
    "Latitude" : -6.125676
  }
}

/* 1 */
{
  "_id" : "seaworld__-6.91_107.60",
  "LongitudeLatitude" : {
    "Longitude" : 107.59730578366,
    "Latitude" : -6.90553846856248
  }
}

/* 2 */
{
  "_id" : "seaside-coffee-at-seaworld__29.46_-98.70",
  "LongitudeLatitude" : {
    "Longitude" : -98.6981248855591,
    "Latitude" : 29.4569375618567
  }
}

/* 3 */
{
  "_id" : "la-quinta-inn-seaworld-hotel__29.45_-98.63",
  "LongitudeLatitude" : {
    "Longitude" : -98.627785,
    "Latitude" : 29.453377
  }
}

Some of the result is way off the 1 degree limit. The query takes 12 seconds.

If I do

db.tablebusiness.find({ "LongitudeLatitude" : { "$within" : { "$box" : [[105, -7], [107, -5]] } }, "indexContents" : "seaworld" }, { "LongitudeLatitude" : 1 }).limit(50);

I got the correct result (there is only 1 result within the box within 2.7 second

Yes all these have proper indexes by the way: enter image description here

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.