<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:49 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>[JAVA-671] Geospatial Query with implied and returns wrong results</title>
                <link>https://jira.mongodb.org/browse/JAVA-671</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;the index is set with : &lt;br/&gt;
db.offerings.ensureIndex( &lt;/p&gt;
{ coord : &quot;2d&quot;, categoryId: 1 }
&lt;p&gt; )  &lt;/p&gt;

&lt;p&gt;while the shell query returns 1 document :&lt;/p&gt;

&lt;p&gt;db.offerings.find( { coord : &lt;/p&gt;
{ $near : [-122,37] }
&lt;p&gt;, categoryId : &apos;212&apos;  } );&lt;/p&gt;

&lt;p&gt;the java version returns two including one with categoryId not equal 212 (212 shows in the debugger as the value of cat)&lt;/p&gt;




&lt;p&gt;     String lat = (String) this.getRequest().getAttributes().get(&quot;lat&quot;);&lt;br/&gt;
	String lon = (String) this.getRequest().getAttributes().get(&quot;long&quot;);&lt;br/&gt;
	String cat = (String) this.getRequest().getAttributes().get(&quot;cat&quot;);&lt;/p&gt;



&lt;p&gt;	DBCollection coll = database.getCollection(&quot;offerings&quot;);	&lt;br/&gt;
	Double locationLongitude = null;&lt;br/&gt;
	Double locationLatitude = null;&lt;/p&gt;

&lt;p&gt;	try &lt;/p&gt;
{
	    locationLongitude =  Double.valueOf(lon.trim()).doubleValue();
	    locationLatitude = Double.valueOf(lat.trim()).doubleValue();
    }
&lt;p&gt;    catch (NumberFormatException e)&lt;/p&gt;
{
        System.out.println(&quot;NumberFormatException: &quot; + e.getMessage());
    }



&lt;p&gt;DBCursor cur = coll.find(new BasicDBObject(&quot;coord&quot;,JSON.parse(&quot;{$near : [ &quot; + locationLongitude + &quot;,&quot; + locationLatitude + &quot; ]}, categoryId : &quot; + cat))); &lt;/p&gt;

&lt;p&gt;	try {&lt;br/&gt;
		JSONObject offeringAsJson = new JSONObject();&lt;br/&gt;
		while(cur.hasNext()) {&lt;br/&gt;
		    DBObject obj = cur.next();&lt;br/&gt;
   System.out.println(&quot;\nGetNext value for categoryId:&quot;+ obj.get(&quot;categoryId&quot;));&lt;/p&gt;

</description>
                <environment>OS X Mountain Lion</environment>
        <key id="53824">JAVA-671</key>
            <summary>Geospatial Query with implied and returns wrong results</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="bruce_ellacott@hotmail.com">Bruce Ellacott</reporter>
                        <labels>
                    </labels>
                <created>Sun, 21 Oct 2012 22:15:28 +0000</created>
                <updated>Mon, 22 Oct 2012 23:32:21 +0000</updated>
                            <resolved>Mon, 22 Oct 2012 01:59:40 +0000</resolved>
                                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="177913" author="bruce_ellacott@hotmail.com" created="Mon, 22 Oct 2012 23:32:21 +0000"  >&lt;p&gt;Thanks for your help with the construction. I spent a lot of time trying to get it to work. I assumed if it got through the parsing it was a valid statement.&lt;/p&gt;</comment>
                            <comment id="177594" author="jeff.yemin" created="Mon, 22 Oct 2012 02:04:20 +0000"  >&lt;p&gt;Also, in general it&apos;s safer to use the QueryBuilder class instead of parsing JSON.  It would look something like:&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;coll.find(QueryBuilder.start(&quot;coord&quot;).near(Double.valueOf(lon.trim()), Double.valueOf(lat.trim())).&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;                         and(&quot;categoryId&quot;).is(cat).get());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="177592" author="jeff.yemin" created="Mon, 22 Oct 2012 01:59:24 +0000"  >&lt;p&gt;Linking to &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-672&quot; title=&quot;JSON.parse should throw an exception if the input string is not fully consumed&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-672&quot;&gt;&lt;del&gt;JAVA-672&lt;/del&gt;&lt;/a&gt;: JSON.parse should throw an exception if the inut string is not fully consumed.&lt;/p&gt;</comment>
                            <comment id="177591" author="jeff.yemin" created="Mon, 22 Oct 2012 01:54:20 +0000"  >&lt;p&gt;There&apos;s a couple of problems.  For one, the String cocatenation in the call to JSON.parse() isn&apos;t quoting the category, so it ends up looking like: &quot;{$near : [ 37.0,-122.0 ]}, categoryId : 212&quot;.  But the reason you&apos;re getting results where category is not equal to 212 is because JSON.parse is silently ignoring everything after the last curly brace, when it should probably throw an exception, as the string is not a fully formed JSON document.  This should work better:&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;  DBCursor cur = coll.find((DBObject) JSON.parse(&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;       &quot;{ coord : {$near : [ &quot; + locationLongitude + &quot;,&quot; + locationLatitude + &quot; ]}, categoryId : &apos;&quot; + cat + &quot;&apos;}&quot;));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="177579" author="bruce_ellacott@hotmail.com" created="Mon, 22 Oct 2012 00:29:30 +0000"  >&lt;p&gt;that&apos;s version mongodb-osx-x86_64-2.2.0 and Java 1.6&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="53835">JAVA-672</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hrk507:</customfieldvalue>

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