Answer the question
In order to leave comments, you need to log in
Why is mongodb not finding a geopoint?
Good evening everyone!
I have a document whose coordinates are in the center of Moscow (TsUM), I added the 2dsphere index to its loc variable and all without errors. But when trying to find it through $box (the search scope is all Moscow time), mongo returns nothing. What am I doing wrong?
Here is the document:
Here is the search query:
$within changed to $geoWithin, lat and lon changed places already. Nothing helps...
Thank you.
Answer the question
In order to leave comments, you need to log in
Edit: removed all previous text.
The bottom line is that for $box you need to set the coordinates in this way:
$box: [
[ <нижний левый угол> ],
[ <верхний правый угол> ]
]
[36.362, 55.38691]
, and for the upper right - the maximum,[38.573, 56.00606]
. As a result, this query covers the point you were looking for:db.places.find({
loc: {
$within: {
$box: [
[36.362, 55.38691],
[38.573, 56.00606]
]
}
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question