[CSHARP-2538] MatchedCount not considering ArrayFilters Created: 04/Mar/19 Updated: 27/Oct/23 Resolved: 01/Apr/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Arun Mahendrakar | Assignee: | Wan Bachtiar |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
windows |
||
| Description |
|
Here's a model I have: Customer
I want to update the AddressStatus to either active or inactive. But if I'm unable to find this address, I'd like to add to the collection. Accordingly, I'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. Filter: var builder = Builders<Customer>.Filter;var builder = Builders<Customer>.Filter; Update: { "$set" : { "PhysicalAddresses.$[cl1].Status" : "Inactive"}} ArrayFilter: var arrayFilterDefinitions = new List<BsonDocumentArrayFilterDefinition<object>>(); This works fine if the address exists. If it doesn't, the UpdateResult response I get is: IsAcknowledged: true 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. 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. Any reason why this is not the case? Thanks, Arun |
| Comments |
| Comment by Wan Bachtiar [ 25/Mar/19 ] | |||||
Hi Arun, Yes, the MatchedCount is a count based on the filter part of the update operation. That's also correct, the ArrayFilter is not considered part of the matched documents, this is because ArrayFilter is supposed to match on a document level not on the collection level. This behaviour is defined in MongoDB server for arrayFilters, and not defined by the drivers. If you would like to upsert a document, that doesn't exist yet, you could do something as below:
Although this would only add a document with value below i.e. there is no CustomerNumber value.
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 mongodb-user group with relevant the information. Regards, | |||||
| Comment by Jeffrey Yemin [ 08/Mar/19 ] | |||||
|
Hi nmarun It's in our queue to investigate. We will get to it as soon as we can! Regards, | |||||
| Comment by Arun Mahendrakar [ 08/Mar/19 ] | |||||
|
Hi Ian, I have not received any update on this ticket yet. Can you please Thanks | |||||
| Comment by Arun Mahendrakar [ 08/Mar/19 ] | |||||
|
@Wan, sir, please let me know if you need any other clarification on my question. | |||||
| Comment by Arun Mahendrakar [ 04/Mar/19 ] | |||||
|
Sorry, there are a couple of typos in the above:
|