<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:08 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-896] GridFS C# driver Unique Index error with sharding</title>
                <link>https://jira.mongodb.org/browse/CSHARP-896</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;When trying to insert a GridFS record into a shard collection and replicateset cluster env using the below code getting error as mentined in the image&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;db.GridFS.Upload(mongoDocs.m_stream[docItem], mongoDocs.m_fileInfo[docItem].Name) &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;We haven&apos;t created any index on the fs.chunks collection.&lt;/p&gt;

&lt;p&gt;Error is :&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;can&apos;t use unique indexes with sharding  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;ns:researchdocs.fs.chunks key: { files_id: 1, n: 1 }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</description>
                <environment></environment>
        <key id="107163">CSHARP-896</key>
            <summary>GridFS C# driver Unique Index error with sharding</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="-1">Unassigned</assignee>
                                    <reporter username="hari.dosapati@credit-suisse.com">Hari Dosapati</reporter>
                        <labels>
                    </labels>
                <created>Wed, 22 Jan 2014 18:01:59 +0000</created>
                <updated>Thu, 23 Jan 2014 16:00:47 +0000</updated>
                            <resolved>Thu, 23 Jan 2014 16:00:47 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="486508" author="hari.dosapati@credit-suisse.com" created="Thu, 23 Jan 2014 16:00:26 +0000"  >&lt;p&gt;I changed shard key and its good now. Thanks for all the support. You can close the ticket.&lt;/p&gt;</comment>
                            <comment id="486211" author="rstam" created="Thu, 23 Jan 2014 01:08:41 +0000"  >&lt;p&gt;You can shard your fs.chunks collection on either:&lt;/p&gt;

&lt;p&gt;1. { files_id : 1 }&lt;br/&gt;
2. { files_id : 1, n : 1 }&lt;/p&gt;

&lt;p&gt;I&apos;ve tested that both shard keys work when using GridFS with the .NET driver.&lt;/p&gt;

&lt;p&gt;It is usually not necessary to shard the fs.files collection because it is so small compared to the fs.chunks collection.&lt;/p&gt;</comment>
                            <comment id="486139" author="matt.kalan@10gen.com" created="Wed, 22 Jan 2014 23:11:05 +0000"  >&lt;p&gt;Hari, as I suspected we do document that the standard shard key for the chunks collection on GridFS is &lt;/p&gt;
{files_id: 1, n: 1}
&lt;p&gt; so that is consistent with what you need as well.  The shard key index is unique also so you won&apos;t get that error.&lt;/p&gt;

&lt;p&gt;You can follow those steps to set up the shard key (as you probably went through already): &lt;br/&gt;
&lt;a href=&quot;http://docs.mongodb.org/manual/tutorial/shard-gridfs-data/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/tutorial/shard-gridfs-data/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="486009" author="matt.kalan@10gen.com" created="Wed, 22 Jan 2014 21:22:21 +0000"  >&lt;p&gt;Hari, just talking with Andre to confirm what you talked about last week, you can generate files._id and then the chunks.files_id is necessarily that same ID to its matching files documents.  You do not need to generate the chunks._id as largely that is not used other than for uniqueness.  When Andre said id last week, he didn&apos;t specify which ID it was.  &lt;/p&gt;

&lt;p&gt;If you shard the files collection on files._id and the chunks collection on chunks.files_id, then the files and its chunks will be archived together assuming the same tag sharding ranges for both collections. &lt;/p&gt;

&lt;p&gt;However, if the GridFS API created the unique index on &lt;/p&gt;
{files_id: 1, n: 1}
&lt;p&gt;, then you would probably get the same error even with that.  We&apos;ll review and figure out the right configuration.  &lt;/p&gt;</comment>
                            <comment id="485953" author="rstam" created="Wed, 22 Jan 2014 20:39:04 +0000"  >&lt;p&gt;I&apos;ve emailed Andrew and Matt to ask them to take a look at this. Maybe there&apos;s something new that I haven&apos;t heard about...&lt;/p&gt;

&lt;p&gt;The _id of the fs.chunks collection is already randomly generated, and you don&apos;t have any control over that (each chunk needs a unique _id anyway). What really matters is the files_id value (which is the same as the _id of the corresponding entry in the fs.files collection), and you are able to set that _id to a custom value if you want. You would use MongoCreateOptions, like this:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var gridFS = database.GridFS;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Stream stream = null; // some stream&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;BsonValue customId = 1234; // your custom _id&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var remoteFileName = &quot;somename&quot;;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var createOptions = new MongoGridFSCreateOptions { Id = customId };&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var result = gridFS.Upload(stream, remoteFileName, createOptions);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="485814" author="hari.dosapati@credit-suisse.com" created="Wed, 22 Jan 2014 18:33:04 +0000"  >&lt;p&gt;As per our requirement, we need to shard by a key thats generated by us, can we create this key by programariclly? If so, please help us with a sample.&lt;br/&gt;
FYI: We worked with Andrew Spiegel and Matt Kalan from your team last week and designed the shard keys based on our requirements.&lt;/p&gt;</comment>
                            <comment id="485809" author="rstam" created="Wed, 22 Jan 2014 18:27:50 +0000"  >&lt;p&gt;That would explain it. Try sharding on the files_id instead.&lt;/p&gt;</comment>
                            <comment id="485802" author="hari.dosapati@credit-suisse.com" created="Wed, 22 Jan 2014 18:25:04 +0000"  >&lt;p&gt;Yes, it is sharded. Shard key is _id&lt;/p&gt;</comment>
                            <comment id="485793" author="rstam" created="Wed, 22 Jan 2014 18:22:13 +0000"  >&lt;p&gt;Is your researchdocs.fs.chunks  collection sharded?&lt;/p&gt;

&lt;p&gt;If so, what is the shard key? &lt;/p&gt;

&lt;p&gt;GridFS requires that the shard key for the chunks collection be the files_id.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="36536" name="GridFS Error.PNG" size="5229" author="hari.dosapati@credit-suisse.com" created="Wed, 22 Jan 2014 18:01:59 +0000"/>
                    </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|hrvk1j:</customfieldvalue>

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