<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:52:50 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-26] Unique index behavior inconsistent</title>
                <link>https://jira.mongodb.org/browse/SERVER-26</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I think I found a bug in the unique index thing.  Sometimes the unique index works, sometimes it doesn&apos;t.  I was writing a test for it and when I do:&lt;/p&gt;

&lt;p&gt;// create non-unique index, add two elements with the same value&lt;br/&gt;
$x = $c-&amp;gt;ensureIndex(array(&apos;x&apos;=&amp;gt;1), !$unique);&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;x&apos;=&amp;gt;0));&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;x&apos;=&amp;gt;0));&lt;/p&gt;

&lt;p&gt;// count is 2&lt;br/&gt;
var_dump($c-&amp;gt;count());&lt;/p&gt;

&lt;p&gt;// create unique index, add two elements with the same value&lt;br/&gt;
$c-&amp;gt;ensureIndex(array(&apos;z&apos;=&amp;gt;1), $unique);&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;z&apos;=&amp;gt;0));&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;z&apos;=&amp;gt;0));&lt;/p&gt;

&lt;p&gt;// I was expecting 3&lt;br/&gt;
var_dump($c-&amp;gt;count());&lt;/p&gt;

&lt;p&gt;...but it&apos;s 4.  Okay, I thought, so maybe the theory is that the &lt;/p&gt;
{&apos;x&apos; : 0}
&lt;p&gt; elements implicitly have the same &apos;z&apos; value, so it&apos;s creating a normal index for &apos;z&apos;, even though I&apos;m asking for a unique index.  This was supported by the fact that this worked:&lt;/p&gt;

&lt;p&gt;// same as above, except setting the &apos;z&apos; field&lt;br/&gt;
$x = $c-&amp;gt;ensureIndex(array(&apos;x&apos;=&amp;gt;1), !$unique);&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;x&apos;=&amp;gt;0, &apos;z&apos;=&amp;gt;1));&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;x&apos;=&amp;gt;0, &apos;z&apos;=&amp;gt;4));&lt;/p&gt;

&lt;p&gt;// count is 2&lt;br/&gt;
var_dump($c-&amp;gt;count());&lt;/p&gt;

&lt;p&gt;$c-&amp;gt;ensureIndex(array(&apos;z&apos;=&amp;gt;1), $unique);&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;z&apos;=&amp;gt;0));&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;z&apos;=&amp;gt;0));&lt;/p&gt;

&lt;p&gt;// count is 3&lt;br/&gt;
var_dump($c-&amp;gt;count());&lt;/p&gt;

&lt;p&gt;So then I added a test creating a third index, to test my theory:&lt;/p&gt;

&lt;p&gt;// create a unique index on &apos;y&apos;, which none of the elements have set&lt;br/&gt;
$c-&amp;gt;ensureIndex(array(&apos;y&apos;=&amp;gt;1), $unique);&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;y&apos;=&amp;gt;0));&lt;br/&gt;
$c-&amp;gt;insert(array(&apos;y&apos;=&amp;gt;0));&lt;/p&gt;

&lt;p&gt;// I was expecting 5, as the unique failed to hold before, but it was 4!&lt;br/&gt;
var_dump($c-&amp;gt;count());&lt;/p&gt;

&lt;p&gt;So, I have no idea what&apos;s going on.  I&apos;m guessing it&apos;s a bug with the unique index code.  Database output for running the whole test:&lt;/p&gt;

&lt;p&gt;Tue Apr 21 10:18:46 connection accepted from 127.0.0.1:50082&lt;br/&gt;
Tue Apr 21 10:18:46 CMD: drop foo.bar&lt;br/&gt;
Tue Apr 21 10:18:46   d-&amp;gt;nIndexes was 2&lt;br/&gt;
Tue Apr 21 10:18:46 info: creating collection foo.bar on add index&lt;br/&gt;
Tue Apr 21 10:18:46 building new index on &lt;/p&gt;
{ x: 1 }
&lt;p&gt; for foo.bar...done for 0 records&lt;br/&gt;
Tue Apr 21 10:18:46 building new index on &lt;/p&gt;
{ z: 1 }
&lt;p&gt; for foo.bar...done for 2 records&lt;br/&gt;
Tue Apr 21 10:18:46 User Exception E11000 duplicate key error&lt;br/&gt;
Tue Apr 21 10:18:46 foo.bar  Caught Assertion insert, continuing&lt;br/&gt;
Tue Apr 21 10:18:46 building new index on &lt;/p&gt;
{ y: 1 }
&lt;p&gt; for foo.bar...Tue Apr 21 10:18:46 User Exception E11000 duplicate key error&lt;/p&gt;

&lt;p&gt;  d-&amp;gt;nIndexes was 3&lt;br/&gt;
Tue Apr 21 10:18:46 foo.system.indexes  Caught Assertion insert, continuing&lt;br/&gt;
Tue Apr 21 10:18:46 User Exception E11000 duplicate key error&lt;br/&gt;
Tue Apr 21 10:18:46 foo.bar  Caught Assertion insert, continuing&lt;br/&gt;
Tue Apr 21 10:18:46 end connection 127.0.0.1:5008&lt;/p&gt;
</description>
                <environment></environment>
        <key id="10084">SERVER-26</key>
            <summary>Unique index behavior inconsistent</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="aaron">Aaron Staple</assignee>
                                    <reporter username="kristina">Kristina Chodorow</reporter>
                        <labels>
                    </labels>
                <created>Tue, 21 Apr 2009 10:37:22 +0000</created>
                <updated>Fri, 22 May 2009 14:30:00 +0000</updated>
                            <resolved>Fri, 22 May 2009 14:24:55 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="10143" author="kristina" created="Fri, 22 May 2009 14:30:00 +0000"  >&lt;p&gt;Thanks for figuring out, that makes sense.&lt;/p&gt;</comment>
                            <comment id="10142" author="aaron" created="Fri, 22 May 2009 14:24:55 +0000"  >&lt;p&gt;Sorry, I was misreading the bug report before &amp;#8211; the described behavior is expected.  Adding a &lt;/p&gt;
{y:1}
&lt;p&gt; unique index fails because multiple existing objects would have &lt;/p&gt;
{y:null}
&lt;p&gt; keys.  Only one &lt;/p&gt;
{y:0}
&lt;p&gt; object may be inserted because each such object has a &lt;/p&gt;
{z:null}
&lt;p&gt; key in the &lt;/p&gt;
{z:1}
&lt;p&gt; unique index so only one such object is allowed.&lt;/p&gt;</comment>
                            <comment id="10141" author="aaron" created="Fri, 22 May 2009 10:50:08 +0000"  >&lt;p&gt;I tried to reproduce this with the js shell but didn&apos;t see the bug.  Going to try running the php version locally.&lt;/p&gt;</comment>
                            <comment id="10114" author="kristina" created="Tue, 19 May 2009 17:29:01 +0000"  >&lt;p&gt;no, still broken.&lt;/p&gt;</comment>
                            <comment id="10093" author="eliot" created="Fri, 15 May 2009 19:59:03 +0000"  >&lt;p&gt;did we ever resolve this?&lt;/p&gt;</comment>
                            <comment id="10031" author="kristina" created="Tue, 21 Apr 2009 10:44:06 +0000"  >&lt;p&gt;Sometimes it does and sometimes it doesn&apos;t, though.  It fails when I create it for &apos;x&apos;, but succeeds for &apos;y&apos;.&lt;/p&gt;</comment>
                            <comment id="10030" author="eliot" created="Tue, 21 Apr 2009 10:40:29 +0000"  >&lt;p&gt;Take a look at the server log:&lt;br/&gt;
Tue Apr 21 10:18:46 User Exception E11000 duplicate key error&lt;/p&gt;

&lt;p&gt;When you try to create the unique index, it fails because there are 2 objects with the same value for z&lt;/p&gt;

&lt;p&gt;If you call getlasterror() you should get that.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="10000" name="tester.php" size="483" author="kristina" created="Tue, 21 Apr 2009 10:37:22 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>7.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 21 Apr 2009 10:40:29 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        14 years, 39 weeks, 5 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>ian@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            14 years, 39 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>aaron</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>kristina</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpyqf:</customfieldvalue>

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

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

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