<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:46 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-215] Java driver&apos;s ensureIndex() does not preserve order</title>
                <link>https://jira.mongodb.org/browse/JAVA-215</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;From what I understand, the order of the keys in an index is important, since mongo can use any index that has additional keys after the keys required for a query. Thus index(A,B,C) is &lt;em&gt;different&lt;/em&gt; from index(C,B,A)&lt;/p&gt;

&lt;p&gt;1. ensureIndex() takes a BasicDBObject as an argument. &lt;br/&gt;
2. The code:&lt;/p&gt;

&lt;p&gt;    public static String genIndexName( DBObject keys ){&lt;br/&gt;
        String name = &quot;&quot;;&lt;br/&gt;
        for ( String s : keys.keySet() )&lt;/p&gt;
{
            if ( name.length() &amp;gt; 0 )
                name += &quot;_&quot;;
            name += s + &quot;_&quot;;
            Object val = keys.get( s );
            if ( val instanceof Number || val instanceof String )
                name += val.toString().replace( &apos; &apos; , &apos;_&apos; );
        }
&lt;p&gt;        return name;&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;3. Generates a name for a DBObject. When there are multiple keys, &quot;key1&quot;: 1, &quot;key2&quot;:2,  keyset() will return the data in arbitrary order. The name will then be the same for each SET of keys.&lt;br/&gt;
4. in ensureIndex():&lt;/p&gt;

&lt;p&gt;        final String name = options.get( &quot;name&quot; ).toString();&lt;/p&gt;

&lt;p&gt;        if ( _createIndexes.contains( name ) )&lt;br/&gt;
            return;&lt;/p&gt;

&lt;p&gt;Will fail, if any other index with the same keys exist, regardless of order.&lt;/p&gt;

&lt;p&gt;5. Even if that does not fail, and a name is manually supplied, createIndex&apos;s comment implies that it uses a set of fields, which will not preserve order     /** Forces creation of an index on a set of fields, if one does not already exist.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;@param keys an object with a key set of the fields desired for the index&lt;br/&gt;
     */&lt;br/&gt;
    public final void createIndex( final DBObject keys )&lt;br/&gt;
        throws MongoException 
{
        createIndex( keys , defaultOptions( keys ) );
    }&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;6. Mongo behaves correctly when adding indices from the console.&lt;/p&gt;

</description>
                <environment>Java</environment>
        <key id="13682">JAVA-215</key>
            <summary>Java driver&apos;s ensureIndex() does not preserve order</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="5">Cannot Reproduce</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="vijayp">Vijay Pandurangan</reporter>
                        <labels>
                    </labels>
                <created>Fri, 12 Nov 2010 16:09:45 +0000</created>
                <updated>Wed, 22 Dec 2010 23:58:14 +0000</updated>
                            <resolved>Sat, 13 Nov 2010 21:13:57 +0000</resolved>
                                                    <fixVersion>2.4</fixVersion>
                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="20723" author="vijayp" created="Fri, 26 Nov 2010 05:07:41 +0000"  >&lt;p&gt; Hi Eliot,&lt;/p&gt;

&lt;p&gt;I have attempted to recreate this, but it turns out the indexes were&lt;br/&gt;
not being created due to another issue. Sorry for the trouble!&lt;/p&gt;

&lt;p&gt;Vijay&lt;/p&gt;



</comment>
                            <comment id="20721" author="eliot" created="Fri, 26 Nov 2010 05:03:37 +0000"  >&lt;p&gt;@miguel Not sure I understand what the issue is?&lt;/p&gt;</comment>
                            <comment id="20717" author="miguel_abraham" created="Fri, 26 Nov 2010 01:13:57 +0000"  >&lt;p&gt;I think the problem with this way of index is that the map with keys and numbers (ie   &quot;key1&quot;: 1, &quot;key2&quot;:2, ...) is wrong.&lt;/p&gt;

&lt;p&gt;If it is like the one on console, the number after the key means ascending order when 1 and descending order when -1. So i think any non negative would be used as ascending order.&lt;/p&gt;

&lt;p&gt;Just an opinion BTW.&lt;/p&gt;</comment>
                            <comment id="20303" author="auto" created="Sat, 13 Nov 2010 21:28:05 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: more tests for &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-215&quot; title=&quot;Java driver&amp;#39;s ensureIndex() does not preserve order&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-215&quot;&gt;&lt;del&gt;JAVA-215&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
/mongodb/mongo-java-driver/commit/ffa63cf905c437bd6718082ece23733c781ea777&lt;/p&gt;</comment>
                            <comment id="20302" author="eliot" created="Sat, 13 Nov 2010 21:13:57 +0000"  >&lt;p&gt;added more tests - but the code seems correct by all accounts&lt;/p&gt;</comment>
                            <comment id="20301" author="scotthernandez" created="Sat, 13 Nov 2010 17:15:33 +0000"  >&lt;p&gt;BasicDBObject extends BasicBSONObject which extends LinkedHahMap which preserves the order of the inserts. There are many tests which depend on this, and prove it.&lt;/p&gt;

&lt;p&gt;The name is generated correctly based on the order.&lt;/p&gt;

&lt;p&gt;Do you have a test to show a problem?&lt;/p&gt;

&lt;p&gt;Take a look at DBCollectionTest.testGenIndexName() for an example of the tests being done.&lt;/p&gt;</comment>
                            <comment id="20259" author="vijayp" created="Fri, 12 Nov 2010 16:11:26 +0000"  >&lt;p&gt;Note that fixing this could have really bad implications for old code that is performant because the keys were generated in a specific order (!!) &lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10012"><![CDATA[Major Change]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrhclz:</customfieldvalue>

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