Relative Content

Tag Archive for mongodbmongodb-query

When performing a geospatial query, why do the `2d`, and `2dsphere` indexes yield different results for `$near` and `$nearSphere`?

IIUC, $near calculates the Euclidean distance using latitude, and longitude (which I think would be an approximation), whereas $nearSphere calculates the great-circle distance using latitude and longitude (which I think would be more accurate). I read that, depending on the index used (2d, 2dsphere), $near and $nearSphere could yield different results. Why is this? Wouldn’t the index only order the database to make the respective queries faster? For example if using the 2d index, I would presume that the $near query would be faster, and likewise for 2dsphere and $nearSphere. I wouldn’t expect that $near with 2dsphere would not be equal to $near with 2d, as was shown in the linked StackOverflow answer. What is causing this difference?

When performing a geospatial query, why do the `2d`, and `2dsphere` indexes yield different results for `$near` and `$nearSphere`?

IIUC, $near calculates the Euclidean distance using latitude, and longitude (which I think would be an approximation), whereas $nearSphere calculates the great-circle distance using latitude and longitude (which I think would be more accurate). I read that, depending on the index used (2d, 2dsphere), $near and $nearSphere could yield different results. Why is this? Wouldn’t the index only order the database to make the respective queries faster? For example if using the 2d index, I would presume that the $near query would be faster, and likewise for 2dsphere and $nearSphere. I wouldn’t expect that $near with 2dsphere would not be equal to $near with 2d, as was shown in the linked StackOverflow answer. What is causing this difference?

When performing a geospatial query, why do the `2d`, and `2dsphere` indexes yield different results for `$near` and `$nearSphere`?

IIUC, $near calculates the Euclidean distance using latitude, and longitude (which I think would be an approximation), whereas $nearSphere calculates the great-circle distance using latitude and longitude (which I think would be more accurate). I read that, depending on the index used (2d, 2dsphere), $near and $nearSphere could yield different results. Why is this? Wouldn’t the index only order the database to make the respective queries faster? For example if using the 2d index, I would presume that the $near query would be faster, and likewise for 2dsphere and $nearSphere. I wouldn’t expect that $near with 2dsphere would not be equal to $near with 2d, as was shown in the linked StackOverflow answer. What is causing this difference?