<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:42:21 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-2364] Documentation lacking for geospatial queries</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2364</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;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: &lt;a href=&quot;https://stackoverflow.com/questions/51987894/why-do-i-get-a-valid-but-inaccurate-nearsphere-query-when-using-the-typed-metho&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://stackoverflow.com/questions/51987894/why-do-i-get-a-valid-but-inaccurate-nearsphere-query-when-using-the-typed-metho&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&apos;m going to copy and paste parts of my StackOverflow question here to describe the issue:&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&#160;&lt;br/&gt;
{{var query = _col.Find($&quot;{{ location: {{ $nearSphere: {{ $geometry: {{ type: \&quot;Point\&quot;, coordinates: [ &lt;/p&gt;
{lon}
&lt;p&gt;, {lat} ] }}, $maxDistance: {rad} }} }} }}&quot;);}}&lt;/p&gt;

&lt;p&gt;This worked fine. My query was accurate. But wherever possible, I&apos;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:&lt;br/&gt;
&#160;&lt;br/&gt;
&lt;tt&gt;var filter = Builders&amp;lt;Node&amp;gt;.Filter.NearSphere(n =&amp;gt; n.Location, lon, lat, rad);var query2 = _col.Find&amp;lt;Node&amp;gt;(filter);&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;{{}}&lt;/p&gt;

&lt;p&gt;By calling&#160;&lt;tt&gt;.ToString()&lt;/tt&gt;&#160;on the queries generated, I see that the first one turns into...&lt;br/&gt;
&#160;&lt;br/&gt;
{{{find({ &quot;location&quot; : { &quot;$nearSphere&quot; : { &quot;$geometry&quot; : &lt;/p&gt;
{ &quot;type&quot; : &quot;Point&quot;, &quot;coordinates&quot; : [1, 2] }
&lt;p&gt;, &quot;$maxDistance&quot; : 3 } } })}}}&lt;/p&gt;

&lt;p&gt;...which produces an accurate result).&lt;/p&gt;

&lt;p&gt;And the second one turns into...&lt;br/&gt;
&#160;&lt;br/&gt;
{{{find({ &quot;location&quot; : &lt;/p&gt;
{ &quot;$nearSphere&quot; : [1.0, 2.0], &quot;$maxDistance&quot; : 3.0 }
&lt;p&gt; })}}}&lt;/p&gt;

&lt;p&gt;..which has a different form and does not produce an accurate result.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;and then when I found the solution...&amp;#93;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;The code for performing this type of query with version&#160;&lt;tt&gt;2.7&lt;/tt&gt;&#160;of the C# driver is:&lt;br/&gt;
&#160;&lt;br/&gt;
&lt;tt&gt;var filterPoint = GeoJson.Point(new GeoJson2DCoordinates(lon, lat));var filter = new FilterDefinitionBuilder&amp;lt;Node&amp;gt;().NearSphere(n =&amp;gt; n.Location, filterPoint, rad);var query = _col.Find&amp;lt;Node&amp;gt;(filter);&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;{{}}&lt;/p&gt;

&lt;p&gt;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):&lt;/p&gt;

&lt;p&gt;{{}}&lt;br/&gt;
&#160;&lt;br/&gt;
{{public class Node{&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;_id&amp;quot;)&amp;#93;&lt;/span&gt;public long Id &lt;/p&gt;
{ get; set; }&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;location&amp;quot;)&amp;#93;&lt;/span&gt;public GeoJsonPoint&amp;lt;GeoJson2DCoordinates&amp;gt; Location { get; set; }
&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;tags&amp;quot;)&amp;#93;&lt;/span&gt;public BsonDocument Tags { get; set; }}}}{{}}&lt;/p&gt;

&lt;p&gt;{{}}&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;}}{{&lt;/tt&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="593946">CSHARP-2364</key>
            <summary>Documentation lacking for geospatial queries</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="welkie">Matt Welke</reporter>
                        <labels>
                            <label>documentation-needed</label>
                    </labels>
                <created>Fri, 24 Aug 2018 15:32:11 +0000</created>
                <updated>Thu, 31 Mar 2022 00:35:48 +0000</updated>
                                            <version>2.7.0</version>
                                                    <component>Documentation</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="2093448" author="ian@10gen.com" created="Mon, 17 Dec 2018 20:47:38 +0000"  >&lt;p&gt;Thanks for opening this report Matt.&lt;/p&gt;</comment>
                            <comment id="1984953" author="welkie" created="Fri, 24 Aug 2018 15:33:55 +0000"  >&lt;p&gt;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.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|htwux3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>