<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:54:29 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-1383] Use an non-existing field to create index, it should not successfull.</title>
                <link>https://jira.mongodb.org/browse/JAVA-1383</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;When I create index, use a non-existing filed to create, it should throw exception, but the index has been created. &lt;/p&gt;</description>
                <environment>MongoDB 2.6.3</environment>
        <key id="153241">JAVA-1383</key>
            <summary>Use an non-existing field to create index, it should not successfull.</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="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="Rambo">Dong [X]</reporter>
                        <labels>
                    </labels>
                <created>Mon, 18 Aug 2014 08:30:48 +0000</created>
                <updated>Tue, 19 Aug 2014 06:40:49 +0000</updated>
                            <resolved>Tue, 19 Aug 2014 06:25:20 +0000</resolved>
                                    <version>2.12.3</version>
                                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="694814" author="rambo" created="Tue, 19 Aug 2014 06:40:49 +0000"  >&lt;p&gt;Thank you for your explain. I got it.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Rambo&lt;/p&gt;</comment>
                            <comment id="694803" author="ross@10gen.com" created="Tue, 19 Aug 2014 06:25:20 +0000"  >&lt;p&gt;Hi Rambo,&lt;/p&gt;

&lt;p&gt;Just to let you know this really is a &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;SERVER&lt;/a&gt;, &lt;a href=&quot;https://groups.google.com/group/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mailing list&lt;/a&gt; or &lt;a href=&quot;http://stackoverflow.com/questions/tagged/mongodb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;stackoverflow&lt;/a&gt; type question, the JAVA project is specifically for driver based bugs or issues.&lt;/p&gt;

&lt;p&gt;However, to answer in short this is a feature of MongoDB. In the relational database world you can also create an index without having any stored data in a table, however, you do describe a schema upfront.  One of MongoDB&apos;s unique selling points is the fact it supports dynamic schemas through its document model providing more flexibility.  As such in MongoDB you can create an index at any time for any field and there may or may be matching documents at the time of creation.  In fact planning and creating indexes up front is often preferred by DBA&apos;s as there can be some operational impact on creating new indexes on large collections.&lt;/p&gt;

&lt;p&gt;I should also highlight that if your data model is changeable on a document by document basis or you are indexing a rarely stored field then a &lt;a href=&quot;http://docs.mongodb.org/manual/core/index-sparse/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;sparse index&lt;/a&gt; would be more space efficient.&lt;/p&gt;

&lt;p&gt;I hope that clarifies why you can create an index on fields that don&apos;t already exist.&lt;/p&gt;</comment>
                            <comment id="694586" author="rambo" created="Tue, 19 Aug 2014 01:30:25 +0000"  >&lt;p&gt;Hi Jeff,&lt;/p&gt;

&lt;p&gt;   I used java code as below:&lt;/p&gt;

&lt;p&gt;                DB db = mongo.getDB(&quot;Test&quot;);&lt;br/&gt;
		DBCollection dbCollection = db.getCollection(&quot;testCollection&quot;);&lt;br/&gt;
		DBObject indexKey = (DBObject) JSON.parse( &quot;&lt;/p&gt;
{names:1}
&lt;p&gt;&quot; );&lt;br/&gt;
		dbCollection.createIndex(indexKey);&lt;/p&gt;

&lt;p&gt; The &quot;testCollection&quot; is a new created collection, have not create document.  So the field &quot;names&quot; is non-existing for &quot;testCollection&quot; documents.&lt;/p&gt;

&lt;p&gt; Use non-existing field to create index, it should not success.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Rambo&lt;/p&gt;</comment>
                            <comment id="693409" author="jeff.yemin" created="Mon, 18 Aug 2014 11:12:19 +0000"  >&lt;p&gt;Please post a code snippet, explaining what you mean by a non-existing field.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Jeff&lt;/p&gt;</comment>
                    </comments>
                    <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|hs1g8n:</customfieldvalue>

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