Slow performance in mongodb compound geospatial index

342 views
Skip to first unread message

sabber sabber

unread,
May 4, 2016, 3:23:31 PM5/4/16
to mongodb-user
I have a collections called "location" one of which documents look like :

    {
    "_id" : ObjectId("5726ad18bdb861058819ea00"),
    "loc" : {
    "type" : "Point",
    "coordinates" : [
    -90.426407,
    34.850685
    ]
    },
    "name" : "restaurant name",
    "tags" : [
    "Chinese",
    "thai",
    "American",
    "indian"
    ]
    }
and i have the following index :

    db.location.getIndexes()
    [
    {
    "v" : 1,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "chatx.location"
    },
    {
    "v" : 1,
    "key" : {
    "loc" : "2dsphere",
    "tags" : 1
    },
    "name" : "loc_2dsphere_tags_1",
    "ns" : "chatx.location",
    "2dsphereIndexVersion" : 3
    }
    ]

i used tags to identify restaurant food type types. 

I have been trying to find out nearest restaurants based on food(s) type. My query is :

    db.runCommand(
       {
         geoNear: "location",
         near: { type: "Point", coordinates: [-90.426407, 34.850685] },
         limit:10,
         maxDistance:5000,
         spherical: true,
         query: { tags:{$all:["chinese", "thai"]}}
       }
    )


In order to do that i used $geoNear (which is very good performative in 3.2 version ). However when i combine with tags (using $all) , query then becomes slower, which makes sense, because $all searches all the documents based on first element then refines based on other elements. The main reason for a query becomes slower is increasing limit (e.g: 10 to 100 or more) and array elements["thai", "indian", .....]. For example if i search restaurants with 4 food type tags, query becomes super slow rather than if i search restaurants with 1 food type tags.

I was wondering if anybody can help me either figuring out best schema for this collection or providing better query options. 

Kevin Adistambha

unread,
May 13, 2016, 12:01:23 AM5/13/16
to mongodb-user

Hi,

In order to do that i used $geoNear (which is very good performative in 3.2 version ). However when i combine with tags (using $all) , query then becomes slower

Could you clarify a few things:

  • What are the numbers on “fast”, “slow”, and “super slow” (e.g. in milliseconds)?
  • How many documents are in the “location” collection?
  • What is your deployment topology (e.g. standalone, replica set, sharded cluster)?
  • What is the exact version of your MongoDB (i.e. 3.2.6 is the latest in the 3.2 series).
  • Could you also please post the output of the db.runCommand({geoNear ...}) query?

which makes sense, because $all searches all the documents based on first element then refines based on other elements

This is correct, as per the Performance section in the $all manual.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages