<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:13:39 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>[SERVER-7105] Please provide a way to use $hint for Update/FindAndModify, and/or fix the Query Optimizer</title>
                <link>https://jira.mongodb.org/browse/SERVER-7105</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;We&apos;re having an issue where a FindAndModify in our code, in some of our environments/servers, decides to use an index that fails horribly (i.e. is sparse, when we&apos;re querying for nulls), and would like a way to force it to use a correct index.  We&apos;re open to using an Update instead, if it would mean a faster turn-around on this issue.&lt;/p&gt;

&lt;p&gt;Our current example:&lt;/p&gt;

&lt;p&gt;SECONDARY&amp;gt; db.version()&lt;br/&gt;
2.0.3&lt;/p&gt;

&lt;p&gt;SECONDARY&amp;gt; db.ourcollection.getIndexes()&lt;br/&gt;
[&lt;br/&gt;
        {&lt;br/&gt;
                &quot;v&quot; : 1,&lt;br/&gt;
                &quot;key&quot; : &lt;/p&gt;
{
                        &quot;_id&quot; : 1
                }
&lt;p&gt;,&lt;br/&gt;
                &quot;ns&quot; : &quot;ourdb.ourcollection&quot;,&lt;br/&gt;
                &quot;name&quot; : &quot;&lt;em&gt;id&lt;/em&gt;&quot;&lt;br/&gt;
        },&lt;br/&gt;
        {&lt;br/&gt;
                &quot;v&quot; : 1,&lt;br/&gt;
                &quot;key&quot; : &lt;/p&gt;
{
                        &quot;StartedOn&quot; : -1
                }
&lt;p&gt;,&lt;br/&gt;
                &quot;ns&quot; : &quot;ourdb.ourcollection&quot;,&lt;br/&gt;
                &quot;name&quot; : &quot;StartedOn_-1&quot;,&lt;br/&gt;
                &quot;background&quot; : true,&lt;br/&gt;
                &quot;sparse&quot; : true&lt;br/&gt;
        }&lt;br/&gt;
]&lt;/p&gt;

&lt;p&gt;SECONDARY&amp;gt; db.ourcollection.find(&lt;/p&gt;
{ &quot;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), &quot;StartedOn&quot; : null }
&lt;p&gt;).explain()&lt;br/&gt;
{&lt;br/&gt;
        &quot;cursor&quot; : &quot;BtreeCursor StartedOn_-1&quot;,&lt;br/&gt;
        &quot;nscanned&quot; : 30,&lt;br/&gt;
        &quot;nscannedObjects&quot; : 30,&lt;br/&gt;
        &quot;n&quot; : 0,&lt;br/&gt;
        &quot;millis&quot; : 0,&lt;br/&gt;
        &quot;nYields&quot; : 0,&lt;br/&gt;
        &quot;nChunkSkips&quot; : 0,&lt;br/&gt;
        &quot;isMultiKey&quot; : false,&lt;br/&gt;
        &quot;indexOnly&quot; : false,&lt;br/&gt;
        &quot;indexBounds&quot; : &lt;/p&gt;
{
                &quot;StartedOn&quot; : [
                        [
                                null,
                                null
                        ]
                ]
        }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;SECONDARY&amp;gt; db.ourcollection.find(&lt;/p&gt;
{ &quot;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;) }
&lt;p&gt;, &lt;/p&gt;
{ _id: 1, StartedOn: 1 }
&lt;p&gt;).toArray()&lt;br/&gt;
[&lt;/p&gt;
	{
		_id: BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;)
	}
&lt;p&gt;]&lt;/p&gt;

&lt;p&gt;SECONDARY&amp;gt; db.ourcollection.find(&lt;/p&gt;
{ &quot;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), &quot;StartedOn&quot; : null }
&lt;p&gt;).toArray()&lt;br/&gt;
[ ]&lt;/p&gt;</description>
                <environment></environment>
        <key id="51122">SERVER-7105</key>
            <summary>Please provide a way to use $hint for Update/FindAndModify, and/or fix the Query Optimizer</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="aaron">Aaron Staple</assignee>
                                    <reporter username="alyman">Alex Lyman</reporter>
                        <labels>
                    </labels>
                <created>Fri, 21 Sep 2012 19:04:12 +0000</created>
                <updated>Fri, 7 Mar 2014 00:57:42 +0000</updated>
                            <resolved>Mon, 15 Oct 2012 19:24:10 +0000</resolved>
                                                                    <component>Querying</component>
                                        <votes>0</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="173456" author="aaron" created="Wed, 10 Oct 2012 18:36:08 +0000"  >&lt;p&gt;Hi Alex - Are the workarounds working for you?&lt;/p&gt;

&lt;p&gt;I think the question of whether a sparse index should return different results was discussed in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-3918&quot; title=&quot;make sparse indexes error out on {$exists: false} queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-3918&quot;&gt;&lt;del&gt;SERVER-3918&lt;/del&gt;&lt;/a&gt;.  If you don&apos;t have any other concerns I&apos;ll plan to close this ticket.&lt;/p&gt;</comment>
                            <comment id="167572" author="aaron" created="Mon, 24 Sep 2012 22:29:31 +0000"  >&lt;p&gt;Hi Alex,&lt;/p&gt;

&lt;p&gt;As you mentioned, there isn&apos;t a way to hint a find and modify.  In 2.2 we added a policy where $exists:false queries will not use sparse indexes (&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-3918&quot; title=&quot;make sparse indexes error out on {$exists: false} queries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-3918&quot;&gt;&lt;del&gt;SERVER-3918&lt;/del&gt;&lt;/a&gt;).  So with 2.2 you can change the query part of your find and modify to get the results you want:&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;   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;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), &quot;StartedOn&quot; : { $exists : false } }&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;(Note I&apos;m assuming you&apos;re just looking for docs without a StartedOn field.)&lt;/p&gt;

&lt;p&gt;On both 2.0 and 2.2 you can use the following workaround to prevent the sparse StartedOn index from being used:&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;   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;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), { $and:[ { $or:[ { &quot;StartedOn&quot; : null }, { &quot;StartedOn&quot;: null } ] } ] } }&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="167461" author="alyman" created="Mon, 24 Sep 2012 19:05:39 +0000"  >&lt;p&gt;Aaron,&lt;/p&gt;

&lt;p&gt;Our specific case is to set StartedOn if it is not already set, and detect that our process is the one that set it.  In particular, the process that does this runs on multiple servers, in multiple data centers, and after it does set it, broadcasts a message to other processes (not the ones that would be setting this).  Our interface contract specifies that that message gets sent exactly once, thus why we use the &lt;/p&gt;
{StartedOn: null}
&lt;p&gt; predicate. The use of find-and-modify isn&apos;t strictly necessary, but it does save a round-trip getting the document after it has been updated.&lt;/p&gt;

&lt;p&gt;This is a boiled down example of the interaction the process uses:&lt;/p&gt;

&lt;p&gt;PRIMARY&amp;gt; result = db.ourcollection.findAndModify({&lt;br/&gt;
     query: &lt;/p&gt;
{ &quot;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), &quot;StartedOn&quot; : null }
&lt;p&gt;,&lt;br/&gt;
     update: {$set: {StartedOn: ISODate()}},&lt;br/&gt;
     new: true&lt;br/&gt;
});&lt;/p&gt;

&lt;p&gt;if (result != null) &lt;/p&gt;
{ broadcastMessage(result); }</comment>
                            <comment id="167445" author="aaron" created="Mon, 24 Sep 2012 18:46:45 +0000"  >&lt;p&gt;Hi Alex,&lt;/p&gt;

&lt;p&gt;Can you send the find and modify query you are running?  Why do you have a query &lt;/p&gt;
{ &quot;_id&quot; : new BinData(3,&quot;L9UXPwbYdEiSQ68DG7A1iQ==&quot;), &quot;StartedOn&quot; : null }
&lt;p&gt;, would _id be sufficient?&lt;/p&gt;

&lt;p&gt;One general thing you might do is run a find with a hint, get the _id of the document you want, and then update that document.  If you send some more details on what you are doing I might be able to suggest some other solutions.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="14991">SERVER-2677</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="12729">SERVER-1599</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 24 Sep 2012 18:46:45 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        11 years, 19 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ian@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            11 years, 19 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10022"><![CDATA[Windows]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>aaron</customfieldvalue>
            <customfieldvalue>alyman</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrnnxr:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hriyrj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>24288</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hs967z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>