indexing - Compound GeoSpatial Index in MongoDB is not working as intended -


the collection nodesways has following indexes:

> db.nodesways.getindexes()                           [                                                             {                                                             "v" : 1,                                              "key" : {                                                     "_id" : 1                                     },                                                    "name" : "_id_",                                      "ns" : "h595.nodesways"                       },                                                    {                                                             "v" : 1,                                              "key" : {                                                     "amenity" : 1,                                        "geo" : "2dsphere"                            },                                                    "name" : "amenity_1_geo_2dsphere",                    "ns" : "h595.nodesways",                              "2dsphereindexversion" : 2                    },                                                    {                                                             "v" : 1,                                              "key" : {                                                     "geo" : "2dsphere"                            },                                                    "name" : "geo_2dsphere",                              "ns" : "h595.nodesways",                              "2dsphereindexversion" : 2                    }                                             ]  

now following 2 queries should return same result, don't. want nearest 10 restaurants specified point. first query working how should be, second not working intended.

the difference between these 2 queries first 1 uses geo_2dsphere-index , second query amenity_1_geo_2dsphere-index.

> db.nodesways.find( {     geo:{         $nearsphere:{             $geometry:{                 type: "point", coordinates:  [9.7399777,52.3715156]             }         }     }, "amenity":"restaurant",          name: {$exists: true} }, {id:1, name:1}).hint( "geo_2dsphere" ).limit(10)  { "_id" : objectid("53884860e552e471be2b7192"), "id" : "321256694", "name" : "masa" } { "_id" : objectid("53884860e552e471be2b7495"), "id" : "323101271", "name" : "bavarium" } { "_id" : objectid("53884862e552e471be2ba605"), "id" : "442496282", "name" : "naxos" } { "_id" : objectid("53884860e552e471be2b7488"), "id" : "323101189", "name" : "block house" } { "_id" : objectid("53884878e552e471be2d1a41"), "id" : "2453236451", "name" : "maestro" } { "_id" : objectid("53884870e552e471be2c8aab"), "id" : "1992166428", "name" : "weinstube leonardo ristorante" } { "_id" : objectid("53884869e552e471be2c168b"), "id" : "1440320284", "name" : "altdeutsche küche" } { "_id" : objectid("53884861e552e471be2b88f7"), "id" : "353119010", "name" : "mövenpick" } { "_id" : objectid("5388485de552e471be2b2c86"), "id" : "265546900", "name" : "miles" } { "_id" : objectid("53884863e552e471be2bb5d3"), "id" : "532304135", "name" : "globetrotter" }  > db.nodesways.find( {     geo:{         $nearsphere:{             $geometry:{                 type: "point", coordinates:  [9.7399777,52.3715156]             }         }     }, "amenity":"restaurant",          name: {$exists: true} }, {id:1, name:1}).hint( "amenity_1_geo_2dsphere" ).limit(10)  { "_id" : objectid("53884875e552e471be2cf4a8"), "id" : "2110027373", "name" : "schloßhof salder" } { "_id" : objectid("5388485be552e471be2aff19"), "id" : "129985174", "name" : "balkan paradies" } { "_id" : objectid("5388485be552e471be2afeb4"), "id" : "129951134", "name" : "asia dragon" } { "_id" : objectid("53884863e552e471be2ba811"), "id" : "450130115", "name" : "kings palast" } { "_id" : objectid("53884863e552e471be2ba823"), "id" : "450130135", "name" : "restaurant montenegro" } { "_id" : objectid("53884877e552e471be2d053a"), "id" : "2298722569", "name" : "pizzaria da-lucia" } { "_id" : objectid("53884869e552e471be2c152e"), "id" : "1420101752", "name" : "napoli" } { "_id" : objectid("5388485be552e471be2b0028"), "id" : "136710095", "name" : "europa" } { "_id" : objectid("53884862e552e471be2ba5bc"), "id" : "442136241", "name" : "syrtaki" } { "_id" : objectid("53884863e552e471be2ba763"), "id" : "447972565", "name" : "pamukkale" } 

my goal second index to: select restaurants use nearsphere-operator sort them in regards distance specified point

auf wiedersehen

i think should try put geolocation first in index.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -