loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Near filter is very slow

Open TuNi54 opened this issue 8 years ago • 3 comments

Hi,

I have this kind of request for my LoopBack 3 project :


var here = new loopback.GeoPoint({lat:"46.44477", lng:"2.6635"});

Car.find({
      
      limit : 50,
      skip :  0,
      where : {
          testing : "false",

          coords : {
              near : here, 
              maxDistance : "50000", 
              unit : "meters"
          }
      },
      
      include : [{
        relation: "User"
      }]

But the response is very very slow. More than 1 min in local and 15s with Heroku.

Is someone had the same issue ?

Database : mongodb

Thank you

TuNi54 avatar Feb 12 '18 14:02 TuNi54

Hi @TuNi54, thank you for reporting the issue. We don't have bandwidth to take a close look into this problem, but I can at least give you some pointers to get you started.

The first step is to find out what query is sent to MongoDB. For example, you can run your app on your local machine with debug log enabled (DEBUG=loopback:connector*), make the slow query and see what the connector reported.

AFAIK, our MongoDB connector sometimes does not know how to translate a query containing "near" filter into a MongoDB query, in which case it falls back to fetching all records and performing the query in-memory. This would explain the long response times you are seeing.

Possibly related issues:

  • https://github.com/strongloop/loopback/issues/2917
  • https://github.com/strongloop/loopback-connector-mongodb/issues/310

bajtos avatar Mar 20 '18 14:03 bajtos

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 19 '18 15:05 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Jun 02 '18 16:06 stale[bot]