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.