<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:44 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-80] Return Local DateTime by default</title>
                <link>https://jira.mongodb.org/browse/CSHARP-80</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Moved from: &lt;a href=&quot;http://github.com/mongodb/mongo-csharp-driver/issues#issue/4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo-csharp-driver/issues#issue/4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What the most .Net developers expect is that they can save a DateTime.Now to database, load it and get back the correct value.&lt;/p&gt;

&lt;p&gt;Currently the driver returns UTC. Which forces the developers do always convert it to local date by hand which is very uncomfortable.&lt;/p&gt;

&lt;p&gt;MongoDB-CSharp solves that by automatically convert the date to a local date (means the timezone where i am in currently). But the developer is able to deactivate this by configuration.&lt;/p&gt;

&lt;p&gt;I think 95% of all developers are developing apps where they store dates only for the current timezone.&lt;/p&gt;</description>
                <environment></environment>
        <key id="13468">CSHARP-80</key>
            <summary>Return Local DateTime by default</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="robert@mongodb.com">Robert Stam</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Oct 2010 19:37:21 +0000</created>
                <updated>Thu, 20 Mar 2014 14:30:06 +0000</updated>
                            <resolved>Sat, 30 Oct 2010 18:32:56 +0000</resolved>
                                    <version>0.5</version>
                                    <fixVersion>0.7</fixVersion>
                                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="21041" author="robert.schooley" created="Sat, 4 Dec 2010 04:15:27 +0000"  >&lt;p&gt;Not to put words into Testo&apos;s mouth, but I don&apos;t believe either of us were looking to change how the data is stored.&lt;/p&gt;

&lt;p&gt;Robert added the functionality to default to local time in the serialization process, however I am using the raw BsonDocuments, which doesn&apos;t support this feature.  Not a big deal really.&lt;/p&gt;

&lt;p&gt;PS: Thanks Robert for walking me through the above.&lt;/p&gt;</comment>
                            <comment id="21039" author="ianmercer" created="Sat, 4 Dec 2010 01:18:46 +0000"  >&lt;p&gt;Not that it affects the solution since the solution defaults to UTC but the original premise of this issue is at odds with database best practices.  Most DateTimes can and should be stored in UTC and not local time because of the many issues that local time has (e.g. it goes backwards and repeats during DST changes) making it impossible to sort correctly for all times within a year.&lt;/p&gt;</comment>
                            <comment id="20716" author="rstam" created="Thu, 25 Nov 2010 19:14:16 +0000"  >&lt;p&gt;It&apos;s no problem to have an Id property of type string. You just have to assign the unique values yourself.&lt;/p&gt;

&lt;p&gt;I&apos;ve modified the sample program at:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/714723&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/714723&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to use a string Id. I also made the following changes:&lt;/p&gt;

&lt;p&gt;1. Replaced AutoMap with explicit mapping (useful when you want total control)&lt;br/&gt;
2. Changed the FindOne query to query on Id instead of Name&lt;/p&gt;

&lt;p&gt;The &quot;Unexpected element _id&quot; issue should only show up in v0.7. Are you using the latest code from github?&lt;/p&gt;

&lt;p&gt;For the model you describe (Model has Bar which has a Baz) it will be serialized using embedded documents, where the embedded Bar has ALL the properties of Bar (and in turn the embedded Baz has all the properties of Baz). That&apos;s just how serialization of embedded objects is supposed to work.&lt;/p&gt;

&lt;p&gt;If that&apos;s now what you want, then you have to do something different. You could either:&lt;/p&gt;

&lt;p&gt;1. Change your Model so that instead of having a Bar property you only have an Id for the Bar&lt;br/&gt;
2. Write some custom serialization code so that when a Model is saved you only save the Id and not the whole Bar object&lt;/p&gt;

&lt;p&gt;In the second case it will be rather challenging to read a Model back in because you will only have the Id and somehow you have to rehydrate the entire Bar object, so this may not even be possible.&lt;/p&gt;

&lt;p&gt;It&apos;s fine to use BsonDocument directly if that&apos;s what you want. But currently there is no control over how DateTime timezones are handled in a BsonDocument. That only applies to serialization of POCOs.&lt;/p&gt;

&lt;p&gt;Regarding timezones, I highly recommend that you store all your values in UTC. If your application ever has to run in multiple timezones you pretty much have to go with UTC as a common denominator. Even in a single timezone going with UTC in your database can save you from daylight saving time issues.&lt;/p&gt;</comment>
                            <comment id="20713" author="robert.schooley" created="Thu, 25 Nov 2010 18:30:38 +0000"  >&lt;p&gt;Thanks for the sample code.  I have previously tried to go this route but ran into some issues:&lt;/p&gt;

&lt;p&gt;1) My Id property does not know about the implementation type of ObjectId, it is a string. &lt;br/&gt;
    ref: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/16cd629cff9e6454/834503624196bf61?lnk=gst&amp;amp;q=blu#834503624196bf61&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/16cd629cff9e6454/834503624196bf61?lnk=gst&amp;amp;q=blu#834503624196bf61&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is the proper setting: cm.MapIdProperty(c =&amp;gt; c.Id); &lt;br/&gt;
I never got this to work, I get an exception: &quot;Unexpected element: _id&quot; Excepted&lt;/p&gt;

&lt;p&gt;2) Allowing automatic parsing and populating of objects has me a little concerned.&lt;/p&gt;

&lt;p&gt;I have added in more model classes, where Model has a Bar, and Bar can have a Baz, etc.  When I save the Model class I get all of the Bar properties, even though they don&apos;t apply.  &lt;br/&gt;
Reference: &lt;a href=&quot;https://gist.github.com/715734&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/715734&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example take saving a Blog Post.  I could have all the Posts be a nested collection inside of the User document, but let&apos;s say I don&apos;t and I have them as top level collections due to other design factors.  When I save the Post, I want to add the User.Id property.  I don&apos;t want the entire User object saved into the Post.  There are properties for Roles, Password, Email, etc.  These won&apos;t be populated in the case of saving the Post, but they would be sent to the database and be just hanging out in there effectively creating noise, or worse potentially stale data if the fields were populated.&lt;/p&gt;

&lt;p&gt;Using the BsonDocument directly has given me a lot of flexibility at the cost of a little development overhead.  Am I misusing the library or just leaving a little convenience on the table?&lt;/p&gt;


&lt;p&gt;Back to the DateTime challenge, is it possible to have the date time default to local using the BsonDocument approach?  I can&apos;t think of a use case where I want UTC so I can probably go into the source and modify the default there but I would prefer a way to just globally change this setting and not have to customize it for each DateTime property in every Model. &lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="20693" author="rstam" created="Thu, 25 Nov 2010 00:58:06 +0000"  >&lt;p&gt;There is no need to convert your Model instances to and from BsonDocument. You can save and read instances of Model directly to the collection.&lt;/p&gt;

&lt;p&gt;I&apos;ve modified your sample a bit to show what I mean:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/714723&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/714723&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I made some other minor changes to get everything to work:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Added an Id field to the model class&lt;/li&gt;
	&lt;li&gt;Moved the serialization initialization code to the top&lt;/li&gt;
	&lt;li&gt;Changed the class initializer argument to RegisterClassMap (see AutoMap and GetMemberMap)&lt;/li&gt;
	&lt;li&gt;Changed the collection variable to have a default document type of Model&lt;/li&gt;
	&lt;li&gt;Removed the code mapping to and from BsonDocument&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="20691" author="robert.schooley" created="Wed, 24 Nov 2010 23:56:56 +0000"  >&lt;p&gt;Thanks for the reply.  I tried this out and did not seem to get it to work.&lt;/p&gt;

&lt;p&gt;I forked your gist with an example of  what I am trying to accomplish:&lt;br/&gt;
&lt;a href=&quot;https://gist.github.com/714658&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/714658&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="20535" author="rstam" created="Sun, 21 Nov 2010 02:34:38 +0000"  >&lt;p&gt;Sure. For anything that can be done with attributes there should be an equivalent way to do it using initialization code alone for those who wish to keep persistence details out of their model. Here&apos;s a link to a gist of a sample program:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/708380&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/708380&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The relevant lines are:&lt;/p&gt;

&lt;p&gt;public class Model {&lt;br/&gt;
    public DateTime DateTimeProperty &lt;/p&gt;
{ get; set; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;var localTime = new DateTimeSerializationOptions &lt;/p&gt;
{ Kind = DateTimeKind.Local }
&lt;p&gt;;&lt;br/&gt;
BsonClassMap.RegisterClassMap&amp;lt;Model&amp;gt;(cm =&amp;gt; {&lt;br/&gt;
    cm.MapProperty(c =&amp;gt; c.DateTimeProperty)&lt;br/&gt;
        .SetSerializationOptions(localTime);&lt;br/&gt;
});&lt;/p&gt;</comment>
                            <comment id="20532" author="robert.schooley" created="Sun, 21 Nov 2010 01:56:39 +0000"  >&lt;p&gt;Is there a way to do this without using an attribute on the model?&lt;/p&gt;

&lt;p&gt;My model is separate from my implementation.  It does not have a reference to the persistence implementation at all.&lt;/p&gt;</comment>
                            <comment id="19870" author="rstam" created="Sat, 30 Oct 2010 18:32:56 +0000"  >&lt;p&gt;Added BsonDateTimeOptions attribute. Samples include:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Kind = DateTimeKind.Utc)&amp;#93;&lt;/span&gt; // the default&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Kind = DateTimeKind.Local)&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;// the following are for DateTime values intended to store only a Date value (so TimeOfDay component is zero)&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Kind = DateTimeKind.Utc, DateOnly = true)&amp;#93;&lt;/span&gt; // the default&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Kind = DateTimeKind.Local, DateOnly = true&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;// the following specify that DateTime values should be stored as BsonType.String instead of BsonType.DateTime&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Representation = BsonType.String)&amp;#93;&lt;/span&gt;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonDateTimeOptions(Representation = BsonType.String, DateOnly = true)&amp;#93;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="19748" author="testn" created="Thu, 28 Oct 2010 05:44:09 +0000"  >&lt;p&gt;would be nice if I can decorate DateTime property field with an attribute to specify the DateTimeKind i need&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|hrh9t3:</customfieldvalue>

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