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

Update field in array with the latest version of driver (3.1.0)

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 3.1.0
    • Component/s: LINQ3
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      After upgrade the driver version to 3.1.0 the positional update operators “LINQ Expression” used to update a specific item in array do not work anymore:

      How to Reproduce

      the following code was working to update an item in an array 

      // code placeholder
      var builder = Builders<Account>.Filter;
      var filter = builder.Eq(u => u.AccountId, accountId) &
                                   builder.ElemMatch(e => e.PoliciesAcceptingStatus, p => p != null && p.PolicyId == policyStatus.PolicyId);
      var update = Builders<Account>.Update.Set(u => u.PoliciesAcceptingStatus.FirstMatchingElement(), policyStatus);
      var result = await AccountsCollection.UpdateOneAsync(filter, update); 

      I have also changed the update statement to the following using the positional operator with the same exception:

      // code placeholder
                      var update = Builders<Account>.Update.Set("policiesAcceptingStatus.$", policyStatus);   

      above fails with the exception below:

      // code placeholder
      MongoDB.Driver.MongoCommandException: Command update failed: Unknown operator: policyId.
        at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1[TCommandResult].ProcessResponse (MongoDB.Driver.Core.Connections.ConnectionId connectionId, MongoDB.Driver.Core.WireProtocol.Messages.CommandMessage responseMessage) [0x001c9] in <bd3efda028a746ab87825194d4cf8b0d>:0 
        

      Please let me know what has changed in LINQ3 regarding these operators. and how do I fix the above code?

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            sasan.pasha@gmail.com Sasan Pasha
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None