<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:41:43 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>[CSHARP-2137] Creating index through Attributes</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2137</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I need to use a code-first programming method to establish my database. I want it to create the index automatically according to the attribute I wrote on the entity class.&lt;/p&gt;

&lt;p&gt;The java driver: spring-data-mongodb, has already supported this, and this is not hard to implement.&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;</description>
                <environment></environment>
        <key id="477673">CSHARP-2137</key>
            <summary>Creating index through Attributes</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="-1">Unassigned</assignee>
                                    <reporter username="HalfLegend">Half Legend [X]</reporter>
                        <labels>
                    </labels>
                <created>Tue, 2 Jan 2018 09:27:42 +0000</created>
                <updated>Mon, 15 Nov 2021 22:25:24 +0000</updated>
                            <resolved>Fri, 2 Feb 2018 17:32:28 +0000</resolved>
                                                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1793483" author="rstam" created="Fri, 2 Feb 2018 17:32:20 +0000"  >&lt;p&gt;Thanks again for making this suggestion. While the feature has appeal, the complications of actually implementing it are more than we feel are justified, at least at this point, so I&apos;m going to close this ticket as &quot;Won&apos;t Fix&quot;.&lt;/p&gt;</comment>
                            <comment id="1766864" author="james@turnersoftware.com.au" created="Sat, 6 Jan 2018 02:34:02 +0000"  >&lt;p&gt;Just want to chime in here, MongoDB indexes are quite complicated and this probably wouldn&apos;t be a small change. Most of the attributes I have seen so far for MongoDB relate to the BSON mapping however an index attribute isn&apos;t a mapping change, it is a DB change.&lt;/p&gt;

&lt;p&gt;Like what Robert mentioned, there is the question of when the driver could actually create or update the index. If it can&apos;t do it at the mapping stage (as you haven&apos;t yet defined a collection for the index to apply to), it could only reasonably do it at the stage of getting the collection from the database object. That means we could have DB queries and manipulation from simply just getting the collection object.&lt;/p&gt;

&lt;p&gt;The other thing to note is what type of index you would want the attributes to support. &lt;a href=&quot;https://docs.mongodb.com/manual/indexes/#index-types&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MongoDB has many types of indexes&lt;/a&gt; which act in many different ways. For example, you can have compound indexes referencing nested types compared to a single field index. Obviously the driver can already create these indexes but the problem is expressing all the different configurations and options as attributes.&lt;/p&gt;

&lt;p&gt;I actually don&apos;t think this type of change should be part of the core driver. The driver should provide all the functionality to communicate with the database and other libraries or frameworks can augment that interface to provide things like index attributes. Otherwise, the driver will get more bloated if they add every different way people want to interface with it to the database.&lt;/p&gt;

&lt;p&gt;I say all of this because I&apos;ve actually written a &lt;a href=&quot;https://github.com/TurnerSoftware/MongoFramework&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;C# MongoDB library&lt;/a&gt; which augments the driver which adds indexing support via attributes. In my particular case, I had to rewrite the entire way I handle entity mapping in my library to do so. Even then, its not perfect and doesn&apos;t do all the index types or options.&lt;/p&gt;</comment>
                            <comment id="1764982" author="rstam" created="Thu, 4 Jan 2018 15:17:55 +0000"  >&lt;p&gt;Thank you for your feedback. You make a good point that if a feature is opt-in an application writer can evaluate the performance impacts and decide for themselves whether to accept them or not.&lt;/p&gt;

&lt;p&gt;It is still unclear when the driver would create an index based on attributes.&lt;/p&gt;

&lt;p&gt;As a workaround for now you can still create the indexes in your application using the existing API (just not via attributes). See the CreateOne method in the IMongoIndexManager interface (reached via collection.Indexes).&lt;/p&gt;</comment>
                            <comment id="1764723" author="halflegend" created="Thu, 4 Jan 2018 06:34:31 +0000"  >&lt;p&gt;As a matter of fact, I am working on a individual project based on MongoDB. It is a management tool and I don&apos;t want it to be too difficult to use. My end user will never concern about &quot;Indexes&quot;, because they even don&apos;t know what a index is.&lt;/p&gt;

&lt;p&gt; In this case I think it will be better if there could be a attribute to create indexes.&lt;/p&gt;

&lt;p&gt;What&apos;s more, I don&apos;t think it is a good idea to refuse providing a new feature that will not break the existing structure. If this feature will affect the existing framework a lot, and may cause many issues which is working fine without the feature developed, I will not ask for a feature like that.&lt;br/&gt;
However, what need to do is to add a new attribute, nothing else will be changed.&lt;/p&gt;

&lt;p&gt;  &lt;em&gt;If I need it,  I will choose it.&lt;/em&gt;&lt;br/&gt;
  &lt;em&gt;If it will break my project, I will reject it.&lt;/em&gt;&lt;br/&gt;
  &lt;b&gt;It&apos;s up to me, instead of the framework itself.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;For example, Oracle provides &quot;triggers&quot;, but in my team, we are not allowed to use &quot;triggers&quot;, the reason is something like what you mentioned above. Anytime we need a trigger, we will &quot;trigger&quot; them by code. But I still think triggers is a good feature provided by Oracle even if we rejected it.&lt;/p&gt;

&lt;p&gt;Thank you very much&lt;/p&gt;</comment>
                            <comment id="1762978" author="rstam" created="Tue, 2 Jan 2018 16:48:54 +0000"  >&lt;p&gt;We have considered this in the past but have so far decided not to implement such a feature. That&apos;s not to say we would never implement it, but for now let me share some of our reasons.&lt;/p&gt;

&lt;p&gt;1. Indexes are more properly handled by the ops team&lt;/p&gt;

&lt;p&gt;It shouldn&apos;t normally be the responsibility of the programmer to define (in code) what indexes are required. Normally it is an ops consideration which indexes are worth creating, and also very importantly &lt;b&gt;when&lt;/b&gt; to create them so as to not disrupt production systems at the wrong time.&lt;/p&gt;

&lt;p&gt;2. Adding or removing an index shouldn&apos;t require releasing a new version of the application&lt;/p&gt;

&lt;p&gt;This is particularly tricky when the decision is made to remove an index that is no longer required. You could get in to a situation where ops removes the unnecessary index but the application keeps creating it again.&lt;/p&gt;

&lt;p&gt;3. Overhead of ensuring the index exists&lt;/p&gt;

&lt;p&gt;The driver would have to at some point check whether the index exists or not and create it if necessary. It is unclear at what point in time the driver would do this, but the more often it has to do it the more overhead there would be.&lt;/p&gt;

&lt;p&gt;4. Permissions concerns&lt;/p&gt;

&lt;p&gt;Security dictates that an application should run with the least permissions possible. Creating an index requires a very high level permission, one that would usually be better not granted to an application.&lt;/p&gt;

&lt;p&gt;I will leave this ticket open for now to encourage further discussion with the community of users.&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|htepfz:</customfieldvalue>

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