<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:40:21 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-1674] Clarify documentation for when StringObjectIdGenerator would be used</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1674</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I am trying to follow simple steps in the C# driver Quick start but I am hitting a major road block because the driver won&apos;t create an ID for my Id public property.&lt;/p&gt;

&lt;p&gt;If I understand the docs correctly the driver should use the StringIdGenerator to generate an ID for my &lt;/p&gt;

&lt;p&gt;public string Id &lt;/p&gt;
{ get; set; }

&lt;p&gt;property on my models.&lt;/p&gt;

&lt;p&gt;I posted a question on SO about this:&lt;br/&gt;
&lt;a href=&quot;http://stackoverflow.com/questions/37361002/mongodb-2-0-c-sharp-driver-not-creating-id-on-inserts&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://stackoverflow.com/questions/37361002/mongodb-2-0-c-sharp-driver-not-creating-id-on-inserts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I posted the question I also attached &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonId&amp;#93;&lt;/span&gt; attribute to the property if that would made any difference but it still resulted in null ID being used with InsertOne() which at the 2nd retry results in &lt;/p&gt;

&lt;p&gt;A bulk write operation resulted in one or more errors.&lt;br/&gt;
 E11000 duplicate key error collection: testdb.Customer index: &lt;em&gt;id&lt;/em&gt; dup key: { : null }&lt;/p&gt;

&lt;p&gt;(obviously).&lt;/p&gt;

&lt;p&gt;I also tried registering a class map simply with&lt;/p&gt;

&lt;p&gt;BsonClassMap.RegisterClassMap&amp;lt;Customer&amp;gt;();&lt;/p&gt;

&lt;p&gt;and it still would not create a value for the Id property.&lt;/p&gt;</description>
                <environment>Windows 10 x64, MongoDb 3.2.6</environment>
        <key id="288473">CSHARP-1674</key>
            <summary>Clarify documentation for when StringObjectIdGenerator would be used</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="brgrz">Marko Hrovatic</reporter>
                        <labels>
                            <label>driver</label>
                            <label>neweng</label>
                    </labels>
                <created>Sun, 22 May 2016 15:12:14 +0000</created>
                <updated>Fri, 21 Apr 2023 19:32:21 +0000</updated>
                                            <version>2.2.4</version>
                                                    <component>Documentation</component>
                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1308256" author="rstam" created="Tue, 28 Jun 2016 02:45:32 +0000"  >&lt;p&gt;Hi Marko, sorry for not replying sooner but it seemed like you had already found a solution.&lt;/p&gt;

&lt;p&gt;To clarify, the StringObjectIdGenerator is &lt;b&gt;not&lt;/b&gt; used automatically for string _ids, &lt;b&gt;unless&lt;/b&gt; that string is represented externally as an ObjectId.&lt;/p&gt;

&lt;p&gt;So when inserting documents of class A the StringObjectIdGenerator is &lt;b&gt;not&lt;/b&gt; used:&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;public class A&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;{&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;    public string 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;   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;}&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;because the driver has no way of knowing what type of strings might be used as _id values, and there is no particular reason to believe that the StringObjectIdGenerator would be the appropriate one to use.&lt;/p&gt;

&lt;p&gt;However, when inserting documents of class B, the StringObjectIdGenerator &lt;b&gt;would&lt;/b&gt; be used:&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;public class B&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;{&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;    [BsonRepresentation(BsonType.ObjectId)]&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;    public string 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;   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;}&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;Because in this class the _id is &quot;a string represented externally as an ObjectId&quot;. In this case it &lt;b&gt;is&lt;/b&gt; appropriate to use the StringObjectIdGenerator.&lt;/p&gt;

&lt;p&gt;Just to be clear, in class B you are declaring you Id property as type string even though in the database the values are stored as ObjectIds. When saving a document of type B the string value is converted to an ObjectId before saving the document (and an exception would be thrown if the string value is not a valid string representation of an ObjectId).&lt;/p&gt;

&lt;p&gt;I&apos;m going to leave this ticket open as a task to clarify the documentation to avoid confusion about when the StringObjectIdGenerator is used.&lt;/p&gt;</comment>
                            <comment id="1307270" author="brgrz" created="Mon, 27 Jun 2016 13:16:15 +0000"  >&lt;p&gt;In one month no one seemed to care to take a look at this...&lt;/p&gt;</comment>
                            <comment id="1271168" author="brgrz" created="Sun, 22 May 2016 15:41:23 +0000"  >&lt;p&gt;Ok, finally I made this working. I had to put attribute &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonId&amp;#93;&lt;/span&gt; set to StringObjectIdGenerator to Id properties.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonId(IdGenerator = typeof(StringObjectIdGenerator))&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;The docs at &lt;a href=&quot;http://mongodb.github.io/mongo-csharp-driver/2.2/reference/bson/mapping/#id-generators&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongodb.github.io/mongo-csharp-driver/2.2/reference/bson/mapping/#id-generators&lt;/a&gt; are certainly misleading or not clear enough&lt;/p&gt;

&lt;p&gt;&quot;Some of these Id generators are used automatically for commonly used Id types:&lt;/p&gt;

&lt;p&gt;GuidGenerator is used for a Guid&lt;br/&gt;
ObjectIdGenerator is used for an ObjectId&lt;br/&gt;
StringObjectIdGenerator is used for a string represented externally as ObjectId&quot;&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|hslorb:</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>