[SERVER-76728] $box that spans the Antemeridian doesn't work as expected Created: 01/May/23 Updated: 27/Oct/23 Resolved: 19/Jul/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 6.0.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Omer Mizrahi | Assignee: | Yuan Fang |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Server Triage
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
I have a query that uses $box in a $geoWithin. I use Google Maps in my app, and whenever a user views a part of the map that spans across the Antemeridian (where part of the viewport is on one side of it and part of it on the other), we get incorrect results. P.S. - Switching to a Polygon solves this, but it really makes sense for my app to use 2d rather than 2dsphere, and switching would also mean handling projection issues, and I couldn't find a Mongo recommended way of doing this. |
| Comments |
| Comment by Omer Mizrahi [ 23/Jul/23 ] |
|
Indeed you are correct, and when we use the $geometry operator we specify the CRS explicitly. But in this case we're not using the $geometry operator, we're using the $box operator, which has no way of setting CRS AFAIK. I hope this is clear enough. I still think this is a bug and would love to get your input. Thanks, Omer |
| Comment by Yuan Fang [ 19/Jul/23 ] |
|
Hi omer@gable.to, The MongoDB document regarding"Big" Polygons explains that:
In the example you provided, the coordinates [ [142.8925, -67.9184], [-116.5788, -46.5688] ] cover locations that are present in both the eastern and western hemispheres, therefore, it is necessary to include the MongoDB coordinate reference system in the $geometry expression to get the expected result. If you have any further questions, we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums. If the discussion there leads you to suspect a bug in the MongoDB server, then we'd want to investigate it as a possible bug here in the SERVER project. Regards, |
| Comment by Omer Mizrahi [ 15/Jul/23 ] |
|
The "incorrect results" are the same as in the StackOverflow issue. I get the "inverse" of the coordinates I ask for (meaning, for example, data between my latitude points, but everything that's NOT between my longitude points). Example query: `$box: [ [142.8925, -67.9184], [-116.5788, -46.5688] ]`. According to the docs, these should represent the bottom left and top right coordinates, but that's clearly not what happens here - it appears MongoDB treats this as if the coordinates represent bottom right and top left. |
| Comment by Yuan Fang [ 30/Jun/23 ] |
|
Hi omer@gable.to, Thank you for your report. To help us better understand the issue you encountered with $box, could you please provide detailed steps to reproduce the problem? Additionally, kindly elaborate on what are the "incorrect results" and why it is not expected. If the problem you encountered is the same as the link you provided, I think the "Big" Polygons explains, as the polygon span across the eastern and western hemispheres. Regards,
|