<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36: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-210] Add ToArray and ToList methods to BsonArray</title>
                <link>https://jira.mongodb.org/browse/CSHARP-210</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;It would be nice if BsonArray had ToArray and ToList methods so we could write code like:&lt;/p&gt;

&lt;p&gt;var document = new BsonDocument(&quot;array&quot;, new BsonArray &lt;/p&gt;
{ 1, 2, 3 }
&lt;p&gt;);&lt;br/&gt;
var list = document&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;array&amp;quot;&amp;#93;&lt;/span&gt;.AsBsonArray.ToList&amp;lt;int&amp;gt;();&lt;/p&gt;

&lt;p&gt;instead of:&lt;/p&gt;

&lt;p&gt;var list = document&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;array&amp;quot;&amp;#93;&lt;/span&gt;.AsBsonArray.Select(v =&amp;gt; v.AsInt32).ToList();&lt;/p&gt;

&lt;p&gt;or something similar if there&apos;s a better alternative.&lt;/p&gt;</description>
                <environment></environment>
        <key id="16286">CSHARP-210</key>
            <summary>Add ToArray and ToList methods to BsonArray</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="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="robert@mongodb.com">Robert Stam</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Apr 2011 21:42:48 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:32 +0000</updated>
                            <resolved>Mon, 25 Apr 2011 14:10:31 +0000</resolved>
                                    <version>1.0</version>
                                    <fixVersion>1.1</fixVersion>
                                    <component>Feature Request</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="29569" author="rstam" created="Mon, 25 Apr 2011 14:10:31 +0000"  >&lt;p&gt;See previous comments regarding why ToList&amp;lt;T&amp;gt; is not really workable, but I did add a non-generic ToList method to complement the existing ToArray method.&lt;/p&gt;</comment>
                            <comment id="29568" author="rstam" created="Mon, 25 Apr 2011 14:05:34 +0000"  >&lt;p&gt;Turns out that implementing ToList&amp;lt;T&amp;gt; has problems:&lt;/p&gt;

&lt;p&gt;1. There is no foolproof way of converting BsonValue to &amp;lt;T&amp;gt; (conversion depends on what &amp;lt;T&amp;gt; is)&lt;br/&gt;
2. Casting the RawValue involves boxing: (&amp;lt;T&amp;gt;) v.RawValue and only works for some BsonValue subclasses&lt;br/&gt;
3. Use of &amp;lt;T&amp;gt; makes it look like &lt;b&gt;any&lt;/b&gt; type can be used, when in fact only a limited set are valid&lt;/p&gt;

&lt;p&gt;I see the following alternatives:&lt;/p&gt;

&lt;p&gt;1. Leave things as they are (after all, it&apos;s only two method calls: Select and ToList)&lt;br/&gt;
2. Add some special methods (e.g. ToInt32List) for selected primitive types (Double, String, ObjectId, Boolean, DateTime, Int32, Int64)&lt;/p&gt;

&lt;p&gt;Alternative 2 would add 14 new methods to the API, and I suggest that even then it&apos;s still not good enough. Each method leaves lots of room for ambiguity. Take ToInt32List for example:&lt;/p&gt;

&lt;p&gt;1. Should it skip elements that aren&apos;t already Int32 or convert them?&lt;br/&gt;
2. If converting doubles to Int32 should it trunctate, round down, round up? How to handle overflow?&lt;br/&gt;
3. If converting Int64 to Int32 how should overflow be handled?&lt;br/&gt;
4. Should string be convertible to Int32 by parsing? If so, under what CultureInfo?&lt;/p&gt;

&lt;p&gt;My conclusion is that we leave things the way they are. There&apos;s very little extra code that has to be written as is, and you have total control over how you want the conversion to be done.&lt;/p&gt;

&lt;p&gt;NOTE: I actually did add a ToList method to complement the existing ToArray method. It returns a List&amp;lt;BsonValue&amp;gt;.&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|hrh91z:</customfieldvalue>

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