<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:42:50 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-2538] MatchedCount not considering ArrayFilters</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2538</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Here&apos;s a model I have:&lt;/p&gt;

&lt;p&gt;Customer&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;CustomerNumber (unique identifier of the document)&lt;br/&gt;
&#160;- PhysicalAddresses (collection)&lt;br/&gt;
&#160; &#160;- AddressId (unique identifier of each address)&lt;br/&gt;
&#160; &#160;- AddressStatus&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I want to update the AddressStatus to either active or inactive. But if I&apos;m unable to find this address, I&apos;d like to add to the collection.&lt;/p&gt;

&lt;p&gt;Accordingly, I&apos;m doing a $set to modify the AddressStatus. My filter will have the customer number and I have an array filter which has the AddressId condition.&lt;/p&gt;

&lt;p&gt;Filter:&#160;var builder = Builders&amp;lt;Customer&amp;gt;.Filter;var builder = Builders&amp;lt;Customer&amp;gt;.Filter; &lt;br/&gt;
var filter = builder.Eq(Constants.CustomerNumber, &quot;&quot;);&lt;/p&gt;

&lt;p&gt;Update: { &quot;$set&quot; : &lt;/p&gt;
{ &quot;PhysicalAddresses.$[cl1].Status&quot; : &quot;Inactive&quot;}
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;ArrayFilter: var arrayFilterDefinitions = new List&amp;lt;BsonDocumentArrayFilterDefinition&amp;lt;object&amp;gt;&amp;gt;();&lt;br/&gt;
var arrayFilterDefinitions = new List&amp;lt;BsonDocumentArrayFilterDefinition&amp;lt;object&amp;gt;&amp;gt;(); arrayFilterDefinitions.Add(new BsonDocumentArrayFilterDefinition&amp;lt;object&amp;gt;(new BsonDocument(&quot;el1.AddressId&quot;, &quot;98875&quot;)));&lt;/p&gt;

&lt;p&gt;This works fine if the address exists. If it doesn&apos;t, the UpdateResult response I get is:&lt;/p&gt;

&lt;p&gt;IsAcknowledged: true&lt;br/&gt;
MatchedCount: 1&lt;br/&gt;
ModifiedCount: 0&lt;/p&gt;

&lt;p&gt;My question is why is the MatchedCount = 1. Is it because it found the document that was part of the filter? If so, that means the ArrayFilter is not considered towards the match.&lt;/p&gt;

&lt;p&gt;In my opinion, even the array filter is part of the filter itself, so MatchedCount should be more than 0, only if filter AND array filter conditions are satisfied.&lt;/p&gt;

&lt;p&gt;Any reason why this is not the case?&lt;/p&gt;

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

&lt;p&gt;Arun&lt;/p&gt;</description>
                <environment>windows</environment>
        <key id="708544">CSHARP-2538</key>
            <summary>MatchedCount not considering ArrayFilters</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13202">Works as Designed</resolution>
                                        <assignee username="wan.bachtiar@mongodb.com">Wan Bachtiar</assignee>
                                    <reporter username="nmarun">Arun Mahendrakar</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Mon, 4 Mar 2019 04:25:43 +0000</created>
                <updated>Fri, 27 Oct 2023 13:24:58 +0000</updated>
                            <resolved>Mon, 1 Apr 2019 12:58:39 +0000</resolved>
                                    <version>2.7.3</version>
                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="2190067" author="wan.bachtiar" created="Mon, 25 Mar 2019 05:51:59 +0000"  >&lt;blockquote&gt;&lt;p&gt;My question is why is the MatchedCount = 1. Is it because it found the document that was part of the filter? If so, that means the ArrayFilter is not considered towards the match.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Hi Arun,&lt;/p&gt;

&lt;p&gt;Yes, the &lt;tt&gt;MatchedCount&lt;/tt&gt; is a count based on the filter part of the update operation. That&apos;s also correct, the &lt;tt&gt;ArrayFilter&lt;/tt&gt; is not considered part of the matched documents, this is because &lt;tt&gt;ArrayFilter&lt;/tt&gt; is supposed to match on a document level not on the collection level.&lt;/p&gt;

&lt;p&gt;This behaviour is defined in MongoDB server for &lt;a href=&quot;https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/#up._S_[%3Cidentifier%3E]&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;arrayFilters&lt;/a&gt;, and not defined by the drivers.&lt;/p&gt;

&lt;p&gt;If you would like to &lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/db.collection.update/#upsert-option&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;upsert&lt;/a&gt; a document, that doesn&apos;t exist yet, you could do something as below:&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: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var&lt;/span&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; filter = Builders&amp;lt;BsonDocument&amp;gt;.Filter.Eq(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;PhysicalAddresses.AddressId&quot;&lt;/span&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;, &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;98875&quot;&lt;/span&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;);&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: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var&lt;/span&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; update = Builders&amp;lt;BsonDocument&amp;gt;.Update.Set(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;PhysicalAddresses.Status&quot;&lt;/span&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;, &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;Inactive&quot;&lt;/span&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;);&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: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var&lt;/span&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; updateOptions = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&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; UpdateOptions { IsUpsert = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;true&lt;/span&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; };&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: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var&lt;/span&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; result = collection.UpdateOne(filter, update, updateOptions);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;Although this would only add a document with value below i.e. there is no &lt;tt&gt;CustomerNumber&lt;/tt&gt; value.&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;   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;{{PhysicalAddresses:[{AddressId: &quot;98875&quot;, Status:&quot;Inactive&quot;}]}} &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Please note that CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the MongoDB server or C# driver, please post a question on &lt;a href=&quot;https://groups.google.com/forum/#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-user&lt;/a&gt; group with relevant the information.&lt;/p&gt;

&lt;p&gt;Regards, &lt;br/&gt;
 Wan.&lt;/p&gt;</comment>
                            <comment id="2175866" author="jeff.yemin" created="Fri, 8 Mar 2019 16:23:16 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=nmarun&quot; class=&quot;user-hover&quot; rel=&quot;nmarun&quot;&gt;nmarun&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It&apos;s in our queue to investigate.  We will get to it as soon as we can!&lt;/p&gt;


&lt;p&gt;Regards,&lt;br/&gt;
Jeff&lt;/p&gt;</comment>
                            <comment id="2175859" author="nmarun" created="Fri, 8 Mar 2019 16:20:26 +0000"  >&lt;p&gt;Hi Ian, I have not received any update on this ticket yet. Can you please&lt;br/&gt;
provide me with an ETA?&lt;/p&gt;

&lt;p&gt;Thanks&lt;br/&gt;
Arun&lt;/p&gt;

</comment>
                            <comment id="2175440" author="nmarun" created="Fri, 8 Mar 2019 03:23:27 +0000"  >&lt;p&gt;@Wan, sir, please let me know if you need any other clarification on my question.&lt;/p&gt;</comment>
                            <comment id="2168625" author="nmarun" created="Mon, 4 Mar 2019 04:30:15 +0000"  >&lt;p&gt;Sorry, there are a couple of typos in the above:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;The CustomerNumber and PhysicalAddresses are at the same level in the document. It shows PhysicalAddresses indented to me here.&lt;/li&gt;
	&lt;li&gt;I am passing a customer number in the filter though it is showing as &quot;&quot; in the question.&lt;/li&gt;
	&lt;li&gt;The identifier is &quot;cl1&quot; in both the Update and the ArrayFilter.&lt;/li&gt;
&lt;/ol&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|huf42n:</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>