<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:39:17 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-1330] MongoDb Database query for Geo Near using c#</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1330</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I am using Mongo CSharpDriver-2.0.0 version and IMongoCollection Async in my application. My data collection looks as shown in the figure attached(2.png).&lt;br/&gt;
Here I want to perform a Search operation on Venue Details, basically we will give a pair of Latitude and Longitude and it should return a list of Records that are with in the distance of 4000 meters from provided Latitude and Longitude.&lt;br/&gt;
To implement above functionality I am using the below code: This code works fine when I pass a single category.&lt;/p&gt;

&lt;p&gt;IMongoCollection&amp;lt;BusinessDeal&amp;gt; BusinessCollection;&lt;br/&gt;
            BusinessCollection = _database.GetCollection&amp;lt;BusinessDeal&amp;gt;(&quot;BusinessDeals2&quot;);&lt;/p&gt;

&lt;p&gt;            double? rangeInMeters = null;&lt;br/&gt;
            if (rangeInMeters == null)&lt;/p&gt;
            {
                rangeInMeters = 3000;
            }

&lt;p&gt;            //add index for venue.location and category&lt;br/&gt;
            var keyBuilder = Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys;&lt;br/&gt;
            keyBuilder.Geo2DSphere(x =&amp;gt; x.Venuedetails.Select(y =&amp;gt; y.Location)).Ascending(x =&amp;gt; x.Categories.Select(y =&amp;gt; y.Id));&lt;br/&gt;
            keyBuilder.Geo2DSphere(x =&amp;gt; x.Venuedetails.Select(y =&amp;gt; y.Location)).Ascending(x =&amp;gt; x.Accessgroups.Select(y =&amp;gt; y.Id));&lt;/p&gt;

&lt;p&gt;            BsonDocument geoPoint = new BsonDocument&lt;br/&gt;
            {&lt;br/&gt;
                &lt;/p&gt;
{&quot;type&quot;,&quot;Point&quot;}
&lt;p&gt;,&lt;br/&gt;
                {&quot;coordinates&quot;,new BsonArray(new double[]{-84.289156, 34.289156})}&lt;br/&gt;
            };&lt;/p&gt;

&lt;p&gt;            BsonDocument geoNearOptions = new BsonDocument&lt;br/&gt;
            {&lt;br/&gt;
                &lt;/p&gt;
{&quot;spherical&quot;, true}
&lt;p&gt;,&lt;br/&gt;
                &lt;/p&gt;
{&quot;limit&quot;, 300}
&lt;p&gt;,should we do a filter first?&lt;br/&gt;
                &lt;/p&gt;
{&quot;maxDistance&quot;, rangeInMeters}
&lt;p&gt;,              &lt;br/&gt;
                &lt;/p&gt;
{&quot;near&quot;,geoPoint}
&lt;p&gt;,&lt;/p&gt;
                {&quot;distanceField&quot;,&quot;dist&quot;}
&lt;p&gt;            };&lt;/p&gt;

&lt;p&gt;            var stage = new BsonDocumentPipelineStageDefinition&amp;lt;BusinessDeal, BusinessDeal&amp;gt;(new BsonDocument { &lt;/p&gt;
{ &quot;$geoNear&quot;, geoNearOptions }
&lt;p&gt; });&lt;/p&gt;

&lt;p&gt;            var colAggregate = BusinessCollection.Aggregate().AppendStage(stage);&lt;br/&gt;
            var result = BusinessCollection.Aggregate().ToListAsync();&lt;br/&gt;
            _businessDealsList = result.Result;&lt;/p&gt;

&lt;p&gt;The above code is returning all the records that are in the Collection. But there are only 2 records that are 4000 meters of distance. My records are as follows:&lt;br/&gt;
	Latitude1	Longitude1	Latitude2	Longitude2	Distance from Origin in Meters&lt;br/&gt;
Record1	-84.289156	34.289156	-84.288357	34.068686	2414.016&lt;br/&gt;
Record2	-84.289156	34.289156	-84.299477	34.069886	2735.8848&lt;br/&gt;
Record3	-84.289156	34.289156	-84.299477	34.690986	4667.0976&lt;/p&gt;

&lt;p&gt;When I run or Debug the code, it returns all the three records. But it should return only 2 records. Please review the code that I have written and help where I am going wrong. Thanks in advance for your help and support.&lt;/p&gt;</description>
                <environment>Windows</environment>
        <key id="212165">CSHARP-1330</key>
            <summary>MongoDb Database query for Geo Near using c#</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="4">Incomplete</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="arvindachary.n@sparshcom.net">Arvind Chary</reporter>
                        <labels>
                            <label>query</label>
                            <label>question</label>
                    </labels>
                <created>Mon, 22 Jun 2015 10:44:16 +0000</created>
                <updated>Fri, 5 Apr 2019 13:59:15 +0000</updated>
                            <resolved>Mon, 22 Jun 2015 14:38:15 +0000</resolved>
                                    <version>2.0.1</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="946946" author="craiggwilson" created="Mon, 22 Jun 2015 14:38:15 +0000"  >&lt;p&gt;All I can tell you is that the exception seems pretty clear: &lt;tt&gt;&apos;near&apos; field must be point.&lt;/tt&gt; Presumably, the format you are providing to the near field is incorrect and is not recognized as a point. &lt;/p&gt;

&lt;p&gt;I&apos;m going to suggest continuing this discussion in the google groups thread you&apos;ve already started. More eyes on the problem will help solve it faster: &lt;a href=&quot;https://groups.google.com/forum/?pli=1#!topic/mongodb-user/mXKzOAhJ9No&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://groups.google.com/forum/?pli=1#!topic/mongodb-user/mXKzOAhJ9No&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="946848" author="arvindachary.n@sparshcom.net" created="Mon, 22 Jun 2015 13:42:28 +0000"  >&lt;p&gt;I have updated my code as follows:&lt;/p&gt;

&lt;p&gt;            IMongoCollection&amp;lt;BusinessDeal&amp;gt; BusinessCollection;&lt;br/&gt;
            BusinessCollection = _database.GetCollection&amp;lt;BusinessDeal&amp;gt;(&quot;BusinessDeals2&quot;);&lt;/p&gt;

&lt;p&gt;            double? rangeInMeters = null;&lt;br/&gt;
            if (rangeInMeters == null)&lt;/p&gt;
            {
                rangeInMeters = 3000;
            }

&lt;p&gt;            try&lt;br/&gt;
            {&lt;br/&gt;
                //add index for venue.location and category&lt;br/&gt;
                var keyBuilder = Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys;&lt;br/&gt;
                keyBuilder.Geo2DSphere(&quot;Venuedetails.geosonLoc.coordinates&quot;).Ascending(&quot;Categories._id&quot;);&lt;/p&gt;

&lt;p&gt;                keyBuilder.Geo2DSphere(x =&amp;gt; x.Venuedetails.Select(y =&amp;gt; y.Location)).Ascending(x =&amp;gt; x.Categories.Select(y =&amp;gt; y.Id));&lt;br/&gt;
                keyBuilder.Geo2DSphere(x =&amp;gt; x.Venuedetails.Select(y =&amp;gt; y.Location)).Ascending(x =&amp;gt; x.Accessgroups.Select(y =&amp;gt; y.Id));&lt;/p&gt;

&lt;p&gt;                BusinessCollection.Indexes.CreateOneAsync(Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys.Geo2D(&quot;Venuedetails.geosonLoc.coordinates&quot;));&lt;/p&gt;

&lt;p&gt;                var indexes = BusinessCollection.Indexes.ListAsync();&lt;/p&gt;

&lt;p&gt;                BsonDocument geoPoint = new BsonDocument&lt;br/&gt;
                {&lt;br/&gt;
                    &lt;/p&gt;
{&quot;type&quot;,&quot;Point&quot;}
&lt;p&gt;,&lt;br/&gt;
                    {&quot;coordinates&quot;,new BsonArray(new double[]&lt;/p&gt;
{ 29.764254, -95.367403 }
&lt;p&gt;)}&lt;br/&gt;
                };&lt;/p&gt;

&lt;p&gt;                BsonDocument geoNearOptions = new BsonDocument&lt;br/&gt;
                {&lt;br/&gt;
                    &lt;/p&gt;
{&quot;spherical&quot;, true}
&lt;p&gt;,&lt;br/&gt;
                    &lt;/p&gt;
{&quot;limit&quot;, 300}
&lt;p&gt;, //need to test to see what limit is appropriate, should we do a filter first?&lt;br/&gt;
                    &lt;/p&gt;
{&quot;maxDistance&quot;, rangeInMeters}
&lt;p&gt;,&lt;br/&gt;
                    &lt;/p&gt;
{&quot;near&quot;, geoPoint}
&lt;p&gt;,&lt;/p&gt;
                    {&quot;distanceField&quot;, &quot;distinct&quot;}
&lt;p&gt;                };&lt;/p&gt;

&lt;p&gt;                //MongoDB requires $geoNear as the first stage of a pipeline.&lt;br/&gt;
                var stage = new BsonDocumentPipelineStageDefinition&amp;lt;BusinessDeal, BusinessDeal&amp;gt;(new BsonDocument { &lt;/p&gt;
{ &quot;$geoNear&quot;, geoNearOptions }
&lt;p&gt; });&lt;/p&gt;

&lt;p&gt;                var colAggregate = BusinessCollection.Aggregate().AppendStage(stage);&lt;br/&gt;
                //var filter = (dynamic)null;&lt;/p&gt;

&lt;p&gt;                result = BusinessCollection.Aggregate().AppendStage(stage).ToListAsync();&lt;br/&gt;
                _businessDealsList = result.Result;&lt;br/&gt;
            }&lt;br/&gt;
            catch (Exception ex)&lt;/p&gt;
            {
                string str = (ex.InnerException).Message;
            }

&lt;p&gt;When I execute my code I am getting following error message: &quot;Message=Command aggregate failed: exception: geoNear command failed: &lt;/p&gt;
{ errmsg: &quot;exception: &apos;near&apos; field must be point&quot;, code: 17304, ok: 0.0 }
&lt;p&gt;.&quot;&lt;/p&gt;

&lt;p&gt;Can you help me why I am getting this error. Thanks in advance for your help and support.&lt;/p&gt;</comment>
                            <comment id="946815" author="craiggwilson" created="Mon, 22 Jun 2015 13:11:42 +0000"  >&lt;p&gt;Hi Arvind,&lt;/p&gt;

&lt;p&gt;This error is coming back from the server and is likely related to a missing index.  For instance, in your code, the only index you are creating is this: &lt;tt&gt;BusinessCollection.Indexes.CreateOneAsync(Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys.Ascending(&quot;Venuedetails.geosonLoc.coordinates&quot;));&lt;/tt&gt;. However, that isn&apos;t a geo index. You previously had some code about a geo index that is unused.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="946780" author="arvindachary.n@sparshcom.net" created="Mon, 22 Jun 2015 12:08:20 +0000"  >&lt;p&gt;Hello Craig,&lt;br/&gt;
Thanks, for your quick response. I have changed my code as follows:&lt;br/&gt;
IMongoCollection&amp;lt;BusinessDeal&amp;gt; BusinessCollection;&lt;br/&gt;
            BusinessCollection = _database.GetCollection&amp;lt;BusinessDeal&amp;gt;(&quot;BusinessDeals2&quot;);&lt;/p&gt;

&lt;p&gt;            double? rangeInMeters = null;&lt;br/&gt;
            if (rangeInMeters == null)&lt;/p&gt;
            {
                rangeInMeters = 3000;
            }

&lt;p&gt;            //add index for venue.location and category&lt;br/&gt;
            var keyBuilder = Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys;&lt;br/&gt;
            keyBuilder.Geo2DSphere(&quot;Venuedetails.geosonLoc.coordinates&quot;).Ascending(&quot;Categories._id&quot;);&lt;/p&gt;

&lt;p&gt;            BusinessCollection.Indexes.CreateOneAsync(Builders&amp;lt;BusinessDeal&amp;gt;.IndexKeys.Ascending(&quot;Venuedetails.geosonLoc.coordinates&quot;));&lt;br/&gt;
            var indexes = BusinessCollection.Indexes.ListAsync();&lt;/p&gt;

&lt;p&gt;            BsonDocument geoPoint = new BsonDocument&lt;br/&gt;
            {&lt;br/&gt;
                &lt;/p&gt;
{&quot;type&quot;,&quot;Point&quot;}
&lt;p&gt;,&lt;br/&gt;
                {&quot;coordinates&quot;,new BsonArray(new double[]{-84.289156, 34.289156})}&lt;br/&gt;
            };&lt;/p&gt;

&lt;p&gt;            BsonDocument geoNearOptions = new BsonDocument&lt;br/&gt;
            {&lt;br/&gt;
                &lt;/p&gt;
{&quot;spherical&quot;, true}
&lt;p&gt;,&lt;br/&gt;
                &lt;/p&gt;
{&quot;limit&quot;, 300}
&lt;p&gt;, //need to test to see what limit is appropriate, should we do a filter first?&lt;br/&gt;
                &lt;/p&gt;
{&quot;maxDistance&quot;, rangeInMeters}
&lt;p&gt;,&lt;br/&gt;
                &lt;/p&gt;
{&quot;near&quot;, geoPoint}
&lt;p&gt;,&lt;/p&gt;
                {&quot;distanceField&quot;, &quot;distinct&quot;}
&lt;p&gt;            };&lt;/p&gt;

&lt;p&gt;            //MongoDB requires $geoNear as the first stage of a pipeline.&lt;br/&gt;
            var stage = new BsonDocumentPipelineStageDefinition&amp;lt;BusinessDeal, BusinessDeal&amp;gt;(new BsonDocument { &lt;/p&gt;
{ &quot;$geoNear&quot;, geoNearOptions }
&lt;p&gt; });&lt;/p&gt;

&lt;p&gt;            var colAggregate = BusinessCollection.Aggregate().AppendStage(stage);&lt;br/&gt;
            //var filter = (dynamic)null;&lt;/p&gt;

&lt;p&gt;            var result = BusinessCollection.Aggregate().AppendStage(stage).ToListAsync();&lt;br/&gt;
            _businessDealsList = result.Result;&lt;/p&gt;

&lt;p&gt;When execute the above code I am getting error message as &quot;Message=Command aggregate failed: exception: geoNear command failed: &lt;/p&gt;
{ ok: 0.0, errmsg: &quot;can&apos;t get query executor&quot; }
&lt;p&gt;.&quot;. &lt;/p&gt;

&lt;p&gt;Can you help me why I am getting this error. Thanks in advance for your help and support.&lt;/p&gt;
</comment>
                            <comment id="946758" author="craiggwilson" created="Mon, 22 Jun 2015 11:44:51 +0000"  >&lt;p&gt;Hi Arvind,&lt;/p&gt;

&lt;p&gt;In the future, please use the &lt;a href=&quot;https://groups.google.com/forum/?pli=1#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;discussion forum&lt;/a&gt; or stackoverflow.com for questions like this. Our ticket system is reserved for questions and feature requests.&lt;/p&gt;

&lt;p&gt;Your problem is this:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var colAggregate = BusinessCollection.Aggregate().AppendStage(stage);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var result = BusinessCollection.Aggregate().ToListAsync();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;_businessDealsList = result.Result;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;You never run &quot;colAggregate&quot;. You run, instead, an empty pipeline.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="78841" name="2.png" size="66637" author="arvindachary.n@sparshcom.net" created="Mon, 22 Jun 2015 10:44:16 +0000"/>
                    </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|hsajdb:</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>