I´m executing the UpdateMany method of MongoDb collection, the result is always zero updated registers.
I´m using MondoDb.Driver for C# (Version 2.5.0.0)
This is my code that execute a update function by a filter. In my test I find 2 elements and update two elements that I can check it:
public bool UpdateFields(FilterDefinition<BsonDocument> filter, UpdateDefinition<BsonDocument> update)
{
if (dbMongoCollection == null)
{
dbMongoCollection = CreateStandardMongoDbClient();
}
var result = dbMongoCollection.UpdateMany(filter, update);
if (result.IsAcknowledged)
{
return result.MatchedCount > 0 && result.ModifiedCount > 0;
}
return false;
}
Curiously, it always return this values:
result.IsAcknowledged true bool
result.IsModifiedCountAvailable true bool
result.MatchedCount 0 long
result.ModifiedCount 0 long
I´d like to know the number of modified/updated elements.
I will appreciate assistance.
result.MatchedCount 0
indicates that no documents were found that match the provided filter. Make sure dbMongoCollection is pointing to the right database and collection. Perhaps use profiling to get the query received by the server to compare with what you intended to send.