[CSHARP-2673] UpdateOneAsync with ArrayFilters not working Created: 01/Aug/19  Updated: 26/Aug/19  Resolved: 26/Aug/19

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.9.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Sandeep Thammadi Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7



 Description   

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,



 Comments   
Comment by Robert Stam [ 05/Aug/19 ]

Your C# code and shell example are using slightly different filters.

Is it possible that the "$eq" that is present in the C# is throwing things off?

If you used the exact same filters in your C# code as in the shell example does it work?

Generated at Wed Feb 07 21:43:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.