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

UpdateOneAsync with ArrayFilters not working

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.9.0
    • Component/s: API
    • None
    • Environment:
      Windows 7

      Hi,

      I'm trying to update a nested array element in a single document using array filters. The call to UpdateOneAsync succeeds, but the returned matched count and modified count, both are 0.

      Here is how I'm calling the API:
       

       var sectionFilter = new BsonDocumentArrayFilterDefinition<BsonDocument>(new BsonDocument("section.section_id", new BsonDocument("$eq", sectionId))); 
      
      var taskFilter = newBsonDocumentArrayFilterDefinition<BsonDocument>(newBsonDocument("task.task_id", newBsonDocument("$eq", taskId)));  
      
      await collection.UpdateOneAsync(
      Builders<Project>.Filter.Eq(x => x.Id, id),   
      Builders<Project>.Update  
          .Set("sections.$[section].tasks.$[task].title", task.Title),   
      new UpdateOptions() { 
         ArrayFilters = new List<ArrayFilterDefinitions>(){sectionFilter, taskFilter}
      });     

       
      Strangely, if I run the below code directly in MongoDB shell (Robo3T), the document gets updated:

      db.getCollection('Projects').update(
       {_id:ObjectId("5d42a79a3f417606300792cb")},
       {$set: {"sections.$[section].tasks.$[task].title":"Create website 21"}},
       {arrayFilters: [{"section.section_id": "4aff46ec59df4866ad84c6544aff143e"},   {"task.task_id": "5d42a8e13f417606300792ce"}]}
      )

       

      I'm using MongoDB.Driver v 2.9.0-beta2

      Please help!

      Cheers,

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            sandeep.thammadi@complyworth.com Sandeep Thammadi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: