<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:07 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-205] Add Insert Methods to MongoCollection&lt;TDefaultDocument&gt; for improved powershell support</title>
                <link>https://jira.mongodb.org/browse/CSHARP-205</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;As previously stated powershell cannot call generic methods of non-generic classes without nasty reflection. So Added these insert overloads to MongoCollection&amp;lt;TDefaultDocument&amp;gt; allows us to insert documents.&lt;/p&gt;

&lt;p&gt;Powershell script to test:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;We assume that the driver is installed via the MSI.&lt;br/&gt;
#&lt;span class=&quot;error&quot;&gt;&amp;#91;string&amp;#93;&lt;/span&gt; $mongoDriverPath = (Get-ItemProperty &quot;HKLM:\SOFTWARE\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 0.11&quot;).&apos;(default)&apos;;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;string&amp;#93;&lt;/span&gt; $mongoDriverPath = &quot;C:\Program Files (x86)\MongoDB\CSharpDriver 1.0\&quot;&lt;br/&gt;
Add-Type -Path &quot;$($mongoDriverPath)\MongoDB.Bson.dll&quot;;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Bson.BsonDocument&amp;#93;&lt;/span&gt; $doc = @{&lt;br/&gt;
    &quot;_id&quot;= &lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Bson.ObjectId&amp;#93;&lt;/span&gt;::GenerateNewId();&lt;br/&gt;
    &quot;FirstName&quot;= &quot;Justin&quot;;&lt;br/&gt;
    &quot;LastName&quot;= &quot;Dearing&quot;;&lt;br/&gt;
    &quot;PhoneNumbers&quot;= &lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Bson.BsonDocument&amp;#93;&lt;/span&gt; @
{
        &apos;Home&apos;= &apos;718-641-2098&apos;;
        &apos;Mobile&apos;= &apos;646-288-5621&apos;;
    }
&lt;p&gt;;&lt;br/&gt;
};&lt;br/&gt;
#$doc;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Add-Type -Path &quot;$($mongoDriverPath)\MongoDB.Driver.dll&quot;;&lt;/p&gt;

&lt;p&gt;$db = &lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Driver.MongoDatabase&amp;#93;&lt;/span&gt;::Create(&apos;mongodb://localhost/powershell&apos;);&lt;br/&gt;
[MongoDB.Driver.MongoCollection&lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Bson.BsonDocument&amp;#93;&lt;/span&gt;] $collection = $db&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;example1&amp;#39;&amp;#93;&lt;/span&gt;;&lt;br/&gt;
$collection.Insert($doc);&lt;br/&gt;
$collection.FindOneById($doc&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;_id&amp;#39;&amp;#93;&lt;/span&gt;);&lt;/p&gt;</description>
                <environment>Powershell</environment>
        <key id="16172">CSHARP-205</key>
            <summary>Add Insert Methods to MongoCollection&lt;TDefaultDocument&gt; for improved powershell support</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="zippy1981">Justin Dearing</reporter>
                        <labels>
                            <label>powershell</label>
                    </labels>
                <created>Mon, 18 Apr 2011 10:58:39 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:41 +0000</updated>
                            <resolved>Mon, 25 Apr 2011 18:48:46 +0000</resolved>
                                    <version>1.0</version>
                                    <fixVersion>1.1</fixVersion>
                                    <component>Feature Request</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="29587" author="rstam" created="Mon, 25 Apr 2011 18:48:46 +0000"  >&lt;p&gt;Added new non-generic Insert methods.&lt;/p&gt;</comment>
                            <comment id="29580" author="rstam" created="Mon, 25 Apr 2011 16:52:41 +0000"  >&lt;p&gt;I tested a slightly different script to confirm that the new MongoCollection constructor is not needed. Here&apos;s the script I used:&lt;/p&gt;

&lt;p&gt;$mongoDriverPath = &quot;C:\work\10gen\mongodb\mongo-csharp-driver\Driver\bin\Debug&quot;&lt;br/&gt;
add-type -path &quot;$($mongoDriverPath)\MongoDB.Bson.dll&quot;&lt;br/&gt;
add-type -path &quot;$($mongoDriverPath)\MongoDB.Driver.dll&quot;&lt;/p&gt;

&lt;p&gt;$server = &lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB.Driver.MongoServer&amp;#93;&lt;/span&gt;::Create(&quot;mongodb://localhost/?safe=true&quot;)&lt;br/&gt;
$database = $server&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;test&amp;quot;&amp;#93;&lt;/span&gt;&lt;br/&gt;
$collection = $database&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;test&amp;quot;&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;$document = @{&lt;br/&gt;
    FirstName = &quot;John&quot;;&lt;br/&gt;
    LastName = &quot;Doe&quot;;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;$collection.RemoveAll()&lt;br/&gt;
$collection.Insert($document)   &lt;/p&gt;

&lt;p&gt;$fetched = $collection.FindOne()&lt;br/&gt;
$json = $fetched.ToString()&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;System.Console&amp;#93;&lt;/span&gt;::WriteLine($json)&lt;/p&gt;

&lt;p&gt;I think the general rule for Powershell friendliness is: &quot;For every generic method there should be a equivalent non-generic method that Powershell users can call&quot;.&lt;/p&gt;

&lt;p&gt;This rule will also help C# users when they are writing meta data driven code where the types of the documents being inserted are not known at compile time.&lt;/p&gt;</comment>
                            <comment id="29416" author="rstam" created="Thu, 21 Apr 2011 05:04:00 +0000"  >&lt;p&gt;Still don&apos;t see why the constructor is needed. The return value of $db&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;name&amp;quot;&amp;#93;&lt;/span&gt; is MongoCollection&amp;lt;BsonDocument&amp;gt;, NOT MongoCollection. So no cast should be required (and therefore no special constructor needed to support the cast). Is there some weird Powershell thing going on that I&apos;m not seeing?&lt;/p&gt;</comment>
                            <comment id="29415" author="zippy1981" created="Thu, 21 Apr 2011 03:41:11 +0000"  >&lt;p&gt;Robert,&lt;/p&gt;

&lt;p&gt;I agree we should try to understand the ramification of supporting powershell. I&apos;ll move that general discussion to the dev list. To touch on your specific points.&lt;/p&gt;

&lt;p&gt;I don&apos;t think the new keyword is needed, but I will test some more.&lt;/p&gt;

&lt;p&gt;The constructor is needed, take it away and my code doesn&apos;t work. What the constructor does (like the HashTable/Idictionary BsonDocument constructor) is allow Powershell to cast objects. In this case it is casting from a MongoCollection to a MontoCollection&amp;lt;TDefaultDocument&amp;gt;.&lt;/p&gt;

&lt;p&gt;I will make InsertBatch work as well. I will make separate tickets for update and remove as well.&lt;/p&gt;

&lt;p&gt;As far as being &quot;sure,&quot; we can write more unit tests for ambiguous cases. However, without an explicit or implicit case between the two types I don&apos;t see how ambiguity can creep in. &lt;/p&gt;</comment>
                            <comment id="29368" author="rstam" created="Wed, 20 Apr 2011 15:24:19 +0000"  >&lt;p&gt;I&apos;m going to hold off on this until we fully understand all the ramifications of supporting Powershell.&lt;/p&gt;

&lt;p&gt;Comments:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;The two new Insert members in MongoCollection&amp;lt;TDefaultDocument&amp;gt; have compile time warnings (regarding the new keyword)&lt;/li&gt;
	&lt;li&gt;Not sure why the new constructor is needed (in your sample code the value being assigned to $collection is already of the needed type, should be a straight assignment)&lt;/li&gt;
	&lt;li&gt;I was expecting the new non-generic Insert methods to have an additional nominalType parameter&lt;/li&gt;
	&lt;li&gt;If we do this, we should do it for InsertBatch also&lt;/li&gt;
	&lt;li&gt;We need to be &lt;b&gt;sure&lt;/b&gt; any new methods don&apos;t introduce compile time ambiguities&lt;/li&gt;
&lt;/ul&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|hrh933:</customfieldvalue>

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