1

I need to query 300 items among 100,000+ and all of these 300 must be contained inside a set of many circles (hundreds). I am using a MongoDB database and here is a part of my logs:

"command": "{
  count: \"items\",
  query: {
    location.coordinates: {
      $geoWithin: {
        $box: [
          [ 2.172203063964844, 48.78040136289702 ],
          [ 2.506599426269531, 48.98765230234855 ]
        ]
      }
    },
  search: \"rent\", isPublished: true,
  $or: [{
    location.coordinates: {
      $geoWithin: {
        $center: [
          [ 2.512155566998092, 48.96309599735446 ], 0.002204591143019205 ]
        }
      }
    },{
      location.coordinates: {
        $geoWithin: {
          $center: [
            [ 2.316596761508817, 48.88132429394468 ], 0.02168492811759336
          ]
        }
      }
    }, { location.coord...",

I tried to add a geospatial index but the performances are still very bad (around 10 seconds).

I'm building my query with mongoose:

    query.where({
      $or: arrayOfNodes
    });

where a node looks like:

{
    'location.coordinates': 
    {
        $geoWithin: 
        { 
            $center: [ [parseFloat(node.lng), parseFloat(node.lat)],
            reachableRadiusInDegrees] 
        }
    }
}

Do you have and idea how I could improve this query?

  • Could you please provide the query? This looks pretty strange. As far as I can tell from that, you are doing two individual geolocation searches, is that correct? – Markus W Mahlberg Jan 2 '16 at 9:32
  • I'm building my query with mongoose: query.where({ $or: arrayOfNodes }); where a node looks like: { 'location.coordinates': { $geoWithin: { $center: [ [parseFloat(node.lng), parseFloat(node.lat)], reachableRadiusInDegrees] } } } – Frederic Le Feurmou Jan 2 '16 at 11:46
  • I need much more information. What are you trying to accomplish? Why do the different coordinates have different radiuses attached? Please describe the use case as clearly as possible. – Markus W Mahlberg Jan 2 '16 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.