Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11830

geo near query does not cover entire length of equator

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: None
    • Component/s: Geo
    • Environment:
    • ALL
    • Hide

      2.5.5-pre-

      > db.c.insert({loc:{type:"Point",coordinates:[0,0]}})
      Insert WriteResult({ "ok" : 1, "n" : 1 })
      > db.c.insert({loc:{type:"Point",coordinates:[-1,0]}})
      Insert WriteResult({ "ok" : 1, "n" : 1 })
      > db.c.ensureIndex({loc:"2dsphere"})
      > db.c.find({loc:{$nearSphere:{$geometry:{type:"Point",coordinates:[180,0]},$maxDistance:10e1000000}}})
      { "_id" : ObjectId("528fa9b06ce2fec2710a135b"), "loc" : { "type" : "Point", "coordinates" : [  -1,  0 ] } }
      > db.c.find({loc:{$near:{$geometry:{type:"Point",coordinates:[180,0]},$maxDistance:10e1000000}}})
      { "_id" : ObjectId("528fa9b06ce2fec2710a135b"), "loc" : { "type" : "Point", "coordinates" : [  -1,  0 ] } }
      > db.runCommand({geoNear:"c", near:{type:"Point",coordinates:[180,0]},spherical:true})
      {
      	"ns" : "georepro.c",
      	"results" : [
      		{
      			"dis" : 19926073.25883961,
      			"obj" : {
      				"_id" : ObjectId("528fa9b06ce2fec2710a135b"),
      				"loc" : {
      					"type" : "Point",
      					"coordinates" : [
      						-1,
      						0
      					]
      				}
      			}
      		}
      	],
      	"stats" : {
      		"nscanned" : 2,
      		"avgDistance" : 19926073.25883961,
      		"maxDistance" : 19926073.25883961,
      		"time" : 7
      	},
      	"ok" : 1
      }
      

      2.4.9-pre-

      > db.c.insert({loc:{type:"Point",coordinates:[0,0]}})
      > db.c.insert({loc:{type:"Point",coordinates:[-1,0]}})
      > db.c.ensureIndex({loc:"2dsphere"})
      > db.c.find({loc:{$nearSphere:{$geometry:{type:"Point",coordinates:[180,0]},$maxDistance:10e1000000}}})
      { "_id" : ObjectId("528fa9b05142cd7d1e23d1bb"), "loc" : { "type" : "Point", "coordinates" : [  -1,  0 ] } }
      { "_id" : ObjectId("528fa99e5142cd7d1e23d1ba"), "loc" : { "type" : "Point", "coordinates" : [  0,  0 ] } }
      > db.c.find({loc:{$near:{$geometry:{type:"Point",coordinates:[180,0]},$maxDistance:10e1000000}}})
      { "_id" : ObjectId("528fa9b05142cd7d1e23d1bb"), "loc" : { "type" : "Point", "coordinates" : [  -1,  0 ] } }
      { "_id" : ObjectId("528fa99e5142cd7d1e23d1ba"), "loc" : { "type" : "Point", "coordinates" : [  0,  0 ] } }
      > db.runCommand({geoNear:"c", near:{type:"Point",coordinates:[180,0]},spherical:true})
      {
      	"ns" : "georepro.c",
      	"results" : [
      		{
      			"dis" : 19926073.261345826,
      			"obj" : {
      				"_id" : ObjectId("528fa9b05142cd7d1e23d1bb"),
      				"loc" : {
      					"type" : "Point",
      					"coordinates" : [
      						-1,
      						0
      					]
      				}
      			}
      		},
      		{
      			"dis" : 20037392.09826071,
      			"obj" : {
      				"_id" : ObjectId("528fa99e5142cd7d1e23d1ba"),
      				"loc" : {
      					"type" : "Point",
      					"coordinates" : [
      						0,
      						0
      					]
      				}
      			}
      		}
      	],
      	"stats" : {
      		"time" : 5,
      		"nscanned" : 2,
      		"avgDistance" : 19981732.679803267,
      		"maxDistance" : 20037392.09826071
      	},
      	"ok" : 1
      }
      
      Show
      2.5.5-pre- > db.c.insert({loc:{type: "Point" ,coordinates:[0,0]}}) Insert WriteResult({ "ok" : 1, "n" : 1 }) > db.c.insert({loc:{type: "Point" ,coordinates:[-1,0]}}) Insert WriteResult({ "ok" : 1, "n" : 1 }) > db.c.ensureIndex({loc: "2dsphere" }) > db.c.find({loc:{$nearSphere:{$geometry:{type: "Point" ,coordinates:[180,0]},$maxDistance:10e1000000}}}) { "_id" : ObjectId( "528fa9b06ce2fec2710a135b" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } > db.c.find({loc:{$near:{$geometry:{type: "Point" ,coordinates:[180,0]},$maxDistance:10e1000000}}}) { "_id" : ObjectId( "528fa9b06ce2fec2710a135b" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } > db.runCommand({geoNear: "c" , near:{type: "Point" ,coordinates:[180,0]},spherical: true }) { "ns" : "georepro.c" , "results" : [ { "dis" : 19926073.25883961, "obj" : { "_id" : ObjectId( "528fa9b06ce2fec2710a135b" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } } ], "stats" : { "nscanned" : 2, "avgDistance" : 19926073.25883961, "maxDistance" : 19926073.25883961, "time" : 7 }, "ok" : 1 } 2.4.9-pre- > db.c.insert({loc:{type: "Point" ,coordinates:[0,0]}}) > db.c.insert({loc:{type: "Point" ,coordinates:[-1,0]}}) > db.c.ensureIndex({loc: "2dsphere" }) > db.c.find({loc:{$nearSphere:{$geometry:{type: "Point" ,coordinates:[180,0]},$maxDistance:10e1000000}}}) { "_id" : ObjectId( "528fa9b05142cd7d1e23d1bb" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } { "_id" : ObjectId( "528fa99e5142cd7d1e23d1ba" ), "loc" : { "type" : "Point" , "coordinates" : [ 0, 0 ] } } > db.c.find({loc:{$near:{$geometry:{type: "Point" ,coordinates:[180,0]},$maxDistance:10e1000000}}}) { "_id" : ObjectId( "528fa9b05142cd7d1e23d1bb" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } { "_id" : ObjectId( "528fa99e5142cd7d1e23d1ba" ), "loc" : { "type" : "Point" , "coordinates" : [ 0, 0 ] } } > db.runCommand({geoNear: "c" , near:{type: "Point" ,coordinates:[180,0]},spherical: true }) { "ns" : "georepro.c" , "results" : [ { "dis" : 19926073.261345826, "obj" : { "_id" : ObjectId( "528fa9b05142cd7d1e23d1bb" ), "loc" : { "type" : "Point" , "coordinates" : [ -1, 0 ] } } }, { "dis" : 20037392.09826071, "obj" : { "_id" : ObjectId( "528fa99e5142cd7d1e23d1ba" ), "loc" : { "type" : "Point" , "coordinates" : [ 0, 0 ] } } } ], "stats" : { "time" : 5, "nscanned" : 2, "avgDistance" : 19981732.679803267, "maxDistance" : 20037392.09826071 }, "ok" : 1 }

      It seems that $near, $nearSphere and geoNear in version 2.5 of mongodb won't return documents whose longitude is 180 degrees away from that in the coordinates given in the query. Version 2.4 will return these documents.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            luke.lovett Luke Lovett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: