<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:46 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-769] Option, attribute, or convention to suppress discriminator in certain classes</title>
                <link>https://jira.mongodb.org/browse/CSHARP-769</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;It would be useful to have a way to suppress the discriminator for certain classes.&lt;/p&gt;

&lt;p&gt;In my case, all classes that are to be stored in Mongo are descended from an abstract class that &quot;knows&quot; how to store things to Mongo:&lt;/p&gt;

&lt;p&gt;It will store to a collection name based on the actual class name&lt;br/&gt;
It knows how to maintain housekeeping fields like CreateDate, LastUpdateDate, _id generation, and self-Archival and numbering of archive versions.&lt;/p&gt;


&lt;p&gt;These are quite useful in this particular project, and it would be pretty painful to have to implement for each class to be saved to the database (there are currently about 14).&lt;/p&gt;

&lt;p&gt;Because all the business objects are derived from this abstract class, the driver adds a discriminator to each record when it is serialized.   This is quite unnecessary, since each actual class is saved to a separate collection.   &lt;/p&gt;

&lt;p&gt;Can an option be added to the serializer or ClassMap classes, or conventions or attributes, that would allow suppression of these discriminators?    Or is there a way of doing that already?&lt;/p&gt;

&lt;p&gt;I already tried defining a ShouldSerialzet or ShouldSerialize_t method in the base class, but that doesn&apos;t seem to do it.&lt;/p&gt;</description>
                <environment>All</environment>
        <key id="80831">CSHARP-769</key>
            <summary>Option, attribute, or convention to suppress discriminator in certain classes</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="9">Done</resolution>
                                        <assignee username="sridhar">Sridhar Nanjundeswaran</assignee>
                                    <reporter username="curt">Curt Mayers</reporter>
                        <labels>
                    </labels>
                <created>Sun, 30 Jun 2013 22:45:28 +0000</created>
                <updated>Wed, 19 Oct 2016 22:40:31 +0000</updated>
                            <resolved>Tue, 2 Jul 2013 21:54:38 +0000</resolved>
                                    <version>1.6</version>
                                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="372945" author="sridhar" created="Tue, 2 Jul 2013 21:54:38 +0000"  >&lt;p&gt;From an offline exchange: if you want to be able to store one or more subtypes but do not need the discriminator stored as each subtype is stored in a different collection, you could do something like:&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 actualType = (objToBePersisted == null) ? typeof(BaseClass) : objToBePersisted.GetType();&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 nominalType = actualType;&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 = collToBeSavedIn.Save(nominalType, objToBePersisted);&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="372168" author="curt" created="Tue, 2 Jul 2013 02:15:28 +0000"  >&lt;p&gt;Here&apos;s the actual abstract class I&apos;m using, at this point (see attachment).&lt;br/&gt;
   All classes which are saved to Mongo descend from it.&lt;br/&gt;
To get to the &quot;interesting&quot; parts, search for &quot;##############&quot;&lt;/p&gt;

&lt;p&gt;I&apos;m sorry if this has too much specific in it, but I thought it would be&lt;br/&gt;
more useful to send you the actual class&lt;/p&gt;

&lt;p&gt;Here&apos;re the behaviors the class implements:&lt;/p&gt;

&lt;p&gt;      1.  It tracks a record version ID which is incremented on each DB&lt;br/&gt;
save.&lt;/p&gt;

&lt;p&gt;      2.  When a record is updated, a new Archive record is also created&lt;br/&gt;
and written to an Archival DB.&lt;br/&gt;
           The _id of the regular record is an incrementing unsigned&lt;br/&gt;
integer, created with a generator.&lt;br/&gt;
           The _id of the Archival record, on the other hand, is a&lt;br/&gt;
calculated compounding of the&lt;br/&gt;
           regular record&apos;s id, &lt;b&gt;plus&lt;/b&gt; the incrementing version ID.&lt;/p&gt;

&lt;p&gt;      3.  Provenance information (record creation and update dates, and&lt;br/&gt;
persons) are automatically added to the record&lt;br/&gt;
           at the time of db save.&lt;/p&gt;

&lt;p&gt;      4.   There&apos;re two virtual methods to return a collection name:  one&lt;br/&gt;
for regular records, and one for&lt;br/&gt;
            archival records.   Unless overwritten in a descendant class,&lt;br/&gt;
they return the class name,&lt;br/&gt;
           or the class name + &quot;Archive&quot;.&lt;/p&gt;

&lt;p&gt;      5,  Records are saved to a collection name specified by the two&lt;br/&gt;
methods described above,&lt;br/&gt;
          so record types within collections are actually homogeneous  (if&lt;br/&gt;
a descendant class decides&lt;br/&gt;
          to store heterogeneous record types in a single collection, it&lt;br/&gt;
must implement its own&lt;br/&gt;
          selector.&lt;/p&gt;

&lt;p&gt;There are (currently) 14 classes, all of which descend from this abstract&lt;br/&gt;
class:  each is stored into&lt;br/&gt;
a different collection.   Thus there is no need for a discriminator in each&lt;br/&gt;
db record: they are superfluous&lt;br/&gt;
and a waste of disk and memory space.&lt;/p&gt;

&lt;p&gt;I added three sample classes at the bottom of the source file to&lt;br/&gt;
illustrate.   Each of these knows how to store itself,&lt;br/&gt;
keeps provenance information, and keeps a complete archive of all versions&lt;br/&gt;
 (these are all requirements for the project&lt;br/&gt;
I&apos;m working on).   &lt;b&gt;All&lt;/b&gt; of this behavior is interited from the abstract&lt;br/&gt;
base class.  (BTW:  it is not a mature class yet:&lt;br/&gt;
I&apos;m quite sure more base functionality will be added.)&lt;/p&gt;

&lt;p&gt;I would just like a way (perhaps a class attribute) which would allow me to&lt;br/&gt;
suppress the expression&lt;br/&gt;
of the discriminator.   Perhaps something like:&lt;/p&gt;

&lt;p&gt;    &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonSuppressDiscriminator(true)&amp;#93;&lt;/span&gt;&lt;/p&gt;


&lt;p&gt;In the meantime, I&apos;d like to know if there is a way to accomplish this&lt;br/&gt;
through a policy, or a ShouldSerialize function,&lt;br/&gt;
or any other means like that.&lt;/p&gt;

&lt;p&gt;Does this all make sense to you?&lt;/p&gt;

&lt;p&gt;(BTW:  please don&apos;t post the source file to a public place,  it would be a&lt;br/&gt;
violation of my contract).&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Curt&lt;/p&gt;


&lt;p&gt;On Mon, Jul 1, 2013 at 5:37 PM, Sridhar Nanjundeswaran (JIRA) &amp;lt;&lt;/p&gt;
</comment>
                            <comment id="372134" author="sridhar" created="Tue, 2 Jul 2013 00:33:13 +0000"  >&lt;p&gt;Hi Curt,&lt;br/&gt;
Do you have some sample code you could show to illustrate the behavior you expect? I added a simple example to show when and where the discriminator gets written &lt;a href=&quot;https://gist.github.com/sridharn/2c915ba58c6faecc714b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/sridharn/2c915ba58c6faecc714b&lt;/a&gt;. I apologize if you have already experimented with this.&lt;/p&gt;</comment>
                            <comment id="371922" author="curt" created="Mon, 1 Jul 2013 19:45:17 +0000"  >&lt;p&gt;I don&apos;t think you understood the question.   Since I&apos;m using an abstract base class to do the mongo access, and record housekeeping, the nominal and actual classes are ALWAYS different.    Since this base class stores different record types into different collections, there is no need for a discriminator.&lt;/p&gt;</comment>
                            <comment id="371906" author="sridhar" created="Mon, 1 Jul 2013 19:18:24 +0000"  >&lt;p&gt;The driver only adds the discriminator when the actual type and the nominal type are different. If they are the same then it does not add the discriminator. Hence you should be able to suppress the _t field by having the actual and nominal types as the same&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|hrrfgn:</customfieldvalue>

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