[CSHARP-2364] Documentation lacking for geospatial queries Created: 24/Aug/18 Updated: 31/Mar/22 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Documentation |
| Affects Version/s: | 2.7.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Matt Welke | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | documentation-needed | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I had an issue recently figuring out how to perform a $nearSphere query with the strongly-typed methods available in the driver. I could get it to work by creating a filter with a string containing the JSON query syntax, but then the compiler would be unable to help me. I ended up creating a StackOverflow question for it, until I eventually solved it myself by tinkering: https://stackoverflow.com/questions/51987894/why-do-i-get-a-valid-but-inaccurate-nearsphere-query-when-using-the-typed-metho I'm going to copy and paste parts of my StackOverflow question here to describe the issue: , {lat} ] }}, $maxDistance: {rad} }} }} }}");}} This worked fine. My query was accurate. But wherever possible, I'd like to use the typed methods instead so the compiler can help me in the future, so I looked online to figure out how to code it, and I came up with this after reading a previous StackOverflow answer: The problem is that these generate different queries under the hood, and the query generated by the latter is inaccurate. It catches many more points. {{}} By calling .ToString() on the queries generated, I see that the first one turns into... , "$maxDistance" : 3 } } })}}} ...which produces an accurate result). And the second one turns into... })}}} ..which has a different form and does not produce an accurate result. [and then when I found the solution...] The code for performing this type of query with version 2.7 of the C# driver is: {{}} I also had to make sure I was using the MongoDB GeoJSON point data type in my model (the class I use to perform the queries): {{}} [BsonElement("tags")]public BsonDocument Tags { get; set; }}}}{{}} {{}} }}{{ |
| Comments |
| Comment by Ian Whalen (Inactive) [ 17/Dec/18 ] |
|
Thanks for opening this report Matt. |
| Comment by Matt Welke [ 24/Aug/18 ] |
|
I see the formatting got messy when I copy and pasted that here. I recommend checking out the StackOverflow link to see the issue more clearly. |