<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:59:38 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-2326] &quot;unique: true&quot; in shardcollection command does not check that the index used has been created as unique</title>
                <link>https://jira.mongodb.org/browse/SERVER-2326</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;The uniqueness of the key used as shard key is enforced by:&lt;br/&gt;
1) sharding makes sure a given shard key value can only live in 1 shard.&lt;br/&gt;
2) then within each shard, the unique index on key&lt;/p&gt;

&lt;p&gt;I&apos;m wondering what the &quot;unique: true&quot; actually does when calling&lt;br/&gt;
shardcollection.&lt;br/&gt;
I would think that it just checks that #2 is valid.&lt;br/&gt;
But according to my tests, it wont create the indexes by itself, nor&lt;br/&gt;
force uniqueness on it:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.runCommand( { shardcollection : &quot;mydb.fs.files&quot;, key : &lt;/p&gt;
{ filename: 1 }
&lt;p&gt;, unique: true })&lt;br/&gt;
{&lt;br/&gt;
        &quot;ok&quot; : 0,&lt;br/&gt;
        &quot;errmsg&quot; : &quot;please create an index over the sharding key before sharding.&quot;&lt;br/&gt;
}&lt;br/&gt;
&amp;gt; use mydb&lt;br/&gt;
switched to db mydb&lt;br/&gt;
&amp;gt; db.fs.files.ensureIndex(&lt;/p&gt;
{filename:1}
&lt;p&gt;)&lt;br/&gt;
&amp;gt; use admin&lt;br/&gt;
switched to db admin&lt;br/&gt;
&amp;gt; db.runCommand( { shardcollection : &quot;mydb.fs.files&quot;, key : &lt;/p&gt;
{ filename: 1 }
&lt;p&gt;, unique: true })&lt;/p&gt;
{ &quot;collectionsharded&quot; : &quot;mydb.fs.files&quot;, &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; use mydb&lt;br/&gt;
switched to db mydb&lt;br/&gt;
&amp;gt; db.fs.files.getIndexes()&lt;br/&gt;
[&lt;br/&gt;
        {&lt;br/&gt;
                &quot;name&quot; : &quot;&lt;em&gt;id&lt;/em&gt;&quot;,&lt;br/&gt;
                &quot;ns&quot; : &quot;mydb.fs.files&quot;,&lt;br/&gt;
                &quot;key&quot; : &lt;/p&gt;
{
                        &quot;_id&quot; : 1
                }
&lt;p&gt;,&lt;br/&gt;
                &quot;v&quot; : 0&lt;br/&gt;
        },&lt;br/&gt;
        {&lt;br/&gt;
                &quot;_id&quot; : ObjectId(&quot;4d228a8197d965fe1d2aaf34&quot;),&lt;br/&gt;
                &quot;ns&quot; : &quot;mydb.fs.files&quot;,&lt;br/&gt;
                &quot;key&quot; : &lt;/p&gt;
{
                        &quot;filename&quot; : 1
                }
&lt;p&gt;,&lt;br/&gt;
                &quot;name&quot; : &quot;filename_1&quot;,&lt;br/&gt;
                &quot;v&quot; : 0&lt;br/&gt;
        }&lt;br/&gt;
]&lt;/p&gt;

&lt;p&gt;this turns out to be a bug: the shardcollection command should fail if it was called with &quot;unique: true&quot; but the existing index used is not unique.&lt;/p&gt;</description>
                <environment></environment>
        <key id="14147">SERVER-2326</key>
            <summary>&quot;unique: true&quot; in shardcollection command does not check that the index used has been created as unique</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="greg_10gen">Greg Studer</assignee>
                                    <reporter username="antoine">Antoine Girbal</reporter>
                        <labels>
                    </labels>
                <created>Tue, 4 Jan 2011 18:51:44 +0000</created>
                <updated>Tue, 12 Jul 2016 00:19:19 +0000</updated>
                            <resolved>Wed, 30 Mar 2011 23:28:52 +0000</resolved>
                                                    <fixVersion>1.9.0</fixVersion>
                                    <component>Sharding</component>
                                        <votes>2</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="51359" author="auto" created="Tue, 30 Aug 2011 00:19:03 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;stbrody&apos;, u&apos;name&apos;: u&apos;Spencer T Brody&apos;, u&apos;email&apos;: u&apos;spencer@10gen.com&apos;}
&lt;p&gt;Message: Add more tests for &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2326&quot; title=&quot;&amp;quot;unique: true&amp;quot; in shardcollection command does not check that the index used has been created as unique&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2326&quot;&gt;&lt;del&gt;SERVER-2326&lt;/del&gt;&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-3718&quot; title=&quot;Trying to shard a collection succeeds even without a unique index&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-3718&quot;&gt;&lt;del&gt;SERVER-3718&lt;/del&gt;&lt;/a&gt;.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/ad830c9c07b7e99187719ae8d099835fb684d0a4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/ad830c9c07b7e99187719ae8d099835fb684d0a4&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="27349" author="auto" created="Wed, 30 Mar 2011 23:28:49 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;gregstuder&apos;, u&apos;name&apos;: u&apos;gregs&apos;, u&apos;email&apos;: u&apos;greg@10gen.com&apos;}
&lt;p&gt;Message: fix for &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2326&quot; title=&quot;&amp;quot;unique: true&amp;quot; in shardcollection command does not check that the index used has been created as unique&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2326&quot;&gt;&lt;del&gt;SERVER-2326&lt;/del&gt;&lt;/a&gt;, unique : true semantics&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/69cf8bee0b7ae3135560a1baa5d7f292995129c6&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/69cf8bee0b7ae3135560a1baa5d7f292995129c6&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="22334" author="lexi" created="Thu, 13 Jan 2011 20:14:34 +0000"  >&lt;p&gt;BTW, I&apos;m just about to enable sharding on a 230GB-database, actually trying to use the unique-option.&lt;/p&gt;</comment>
                            <comment id="22032" author="eliot" created="Tue, 4 Jan 2011 18:56:18 +0000"  >&lt;p&gt;Most times people enablesharding its empty, so that&apos;s definitely correct.&lt;/p&gt;</comment>
                            <comment id="22031" author="antoine" created="Tue, 4 Jan 2011 18:54:55 +0000"  >&lt;p&gt;Right now, the only case where &quot;unique: true&quot; works is when it is called on an empty collection, in which case the index gets created automatically.&lt;br/&gt;
To me, it would be cleaner and easier to maintain if shardcollection always relied on a preexisting index, and did not have &quot;unique&quot; option.&lt;br/&gt;
This way we dont have to duplicate options or have inconsistency between ensureIndex and shardCollection.&lt;br/&gt;
Having it work only when collection is empty is not very useful.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 4 Jan 2011 18:56:18 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        12 years, 25 weeks, 2 days 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>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            12 years, 25 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>antoine</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>greg_10gen</customfieldvalue>
            <customfieldvalue>lexi</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrp8y7:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21573</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|ht0ez3:</customfieldvalue>

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