Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2538

MatchedCount not considering ArrayFilters

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.3
    • Component/s: BSON
    • Labels:
    • Environment:
      windows

      Here's a model I have:

      Customer

      • CustomerNumber (unique identifier of the document)
         - PhysicalAddresses (collection)
           - AddressId (unique identifier of each address)
           - AddressStatus

      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;
      var filter = builder.Eq(Constants.CustomerNumber, "");

      Update: { "$set" :

      { "PhysicalAddresses.$[cl1].Status" : "Inactive"}

      }

      ArrayFilter: var arrayFilterDefinitions = new List<BsonDocumentArrayFilterDefinition<object>>();
      var arrayFilterDefinitions = new List<BsonDocumentArrayFilterDefinition<object>>(); arrayFilterDefinitions.Add(new BsonDocumentArrayFilterDefinition<object>(new BsonDocument("el1.AddressId", "98875")));

      This works fine if the address exists. If it doesn't, the UpdateResult response I get is:

      IsAcknowledged: true
      MatchedCount: 1
      ModifiedCount: 0

      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

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            nmarun Arun Mahendrakar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: