<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:47:48 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-4293] Update with aggregation pipeline fails when used on a OfTypeMongoCollection (OfType&lt;T&gt;)</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4293</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;When trying to update documents with an aggregation pipeline this fails when used on a OfTypeMongoCollection that was aquired through OfType&amp;lt;T&amp;gt;(). The error message is:&lt;/em&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&apos;Unable to cast object of type &apos;MongoDB.Bson.BsonArray&apos; to type &apos;MongoDB.Bson.BsonDocument&apos;.&apos;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This happens independent of the pipeline stages; even an empty pipeline leads to this error.&lt;/em&gt;&#160;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Pleaseprovidetheversionofthedriver.Ifapplicable%2CpleaseprovidetheMongoDBserverversionandtopology%28standalone%2Creplicaset%2Corshardedcluster%29.&quot;&gt;&lt;/a&gt;Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).&lt;/h4&gt;

&lt;p&gt;2.17.1, tested both on MongoDB 5.0.9 Community and ATLAS 5.0.10 Enterprise&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;var pipeline = new EmptyPipelineDefinition&amp;lt;DerivedClass&amp;gt;()&lt;br/&gt;
&#160; &#160; .AppendStage&amp;lt;DerivedClass, DerivedClass, DerivedClass&amp;gt;(new BsonDocument&lt;br/&gt;
&#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; {&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &quot;$set&quot;,&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; new BsonDocument&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; \{ nameof(DerivedClass.Value), &quot;Pipeline&quot; }
&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; });&lt;br/&gt;
var update = Builders&amp;lt;DerivedClass&amp;gt;.Update.Pipeline(pipeline);&lt;br/&gt;
// Fails with: &apos;Unable to cast object of type &apos;MongoDB.Bson.BsonArray&apos; to type &apos;MongoDB.Bson.BsonDocument&apos;.&apos;&lt;br/&gt;
collDerived.UpdateOne(&lt;br/&gt;
&#160; &#160; x =&amp;gt; x.Key == &quot;TestKey&quot;,&lt;br/&gt;
&#160; &#160; pipeline,&lt;br/&gt;
&#160; &#160; new UpdateOptions() { IsUpsert = true });&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;AdditionalBackground&quot;&gt;&lt;/a&gt;Additional Background&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;See attached .cs-file for a sample that demonstrates the error.&lt;/em&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2111728">CSHARP-4293</key>
            <summary>Update with aggregation pipeline fails when used on a OfTypeMongoCollection (OfType&lt;T&gt;)</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="13201">Fixed</resolution>
                                        <assignee username="dmitry.lukyanov@mongodb.com">Dmitry Lukyanov</assignee>
                                    <reporter username="m.wildgruber@sevantage.de">Markus Wildgruber</reporter>
                        <labels>
                    </labels>
                <created>Thu, 11 Aug 2022 16:09:59 +0000</created>
                <updated>Sat, 28 Oct 2023 11:47:06 +0000</updated>
                            <resolved>Thu, 25 Aug 2022 11:59:16 +0000</resolved>
                                    <version>2.17.1</version>
                                    <fixVersion>2.18.0</fixVersion>
                                    <component>CRUD</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4776198" author="xgen-internal-githook" created="Thu, 25 Aug 2022 11:58:48 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Dmitry Lukyanov&apos;, &apos;email&apos;: &apos;dmitry.lukyanov@mongodb.com&apos;, &apos;username&apos;: &apos;DmitryLukyanov&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4293&quot; title=&quot;Update with aggregation pipeline fails when used on a OfTypeMongoCollection (OfType&amp;lt;T&amp;gt;)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4293&quot;&gt;&lt;del&gt;CSHARP-4293&lt;/del&gt;&lt;/a&gt;: Update with aggregation pipeline fails when used on a OfTypeMongoCollection (OfType&amp;lt;T&amp;gt;). (#869)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/786e32440a3a14b1125a1e98e4495ac38bbc9b3b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/786e32440a3a14b1125a1e98e4495ac38bbc9b3b&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4750062" author="dmitry.lukyanov" created="Mon, 15 Aug 2022 14:51:54 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=m.wildgruber%40sevantage.de&quot; class=&quot;user-hover&quot; rel=&quot;m.wildgruber@sevantage.de&quot;&gt;m.wildgruber@sevantage.de&lt;/a&gt;, thanks for your report, I can confirm that it&apos;s a bug. We&apos;ve scheduled this work, please follow to this ticket for updates.&lt;/p&gt;</comment>
                            <comment id="4746184" author="m.wildgruber@sevantage.de" created="Fri, 12 Aug 2022 08:03:51 +0000"  >&lt;p&gt;The problem was discovered when trying to perform a BulkWriteAsync on the OfTypeMongoCollection. This is not part of the sample code. Please also check BulkWriteAsync with UpdateOnModels that are based on an aggregation pipeline.&#160;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="2410016">CSHARP-4745</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="395410" name="Program.cs" size="1472" author="m.wildgruber@sevantage.de" created="Thu, 11 Aug 2022 16:09:28 +0000"/>
                    </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|hr48xi:oao</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>