using MongoDB C# Driver, and trying to use DeleteManyAsync() with retryable writes, so I configured it, and included ?retrywrites=true in the connection string.
Tried using DeleteManyAsync() and getting this error
```A write operation resulted in an error. WriteError: { Category : “Uncategorized”, Code : 72, Message : “Cannot use (or request) retryable writes with limit=0” }.`
So I set ?retrywrites=false, and ``DeleteManyAsync()` started working.
I saw in the documentation for retryable writes that DeleteMany isn’t supported, only single document operations are - but I would expect DeleteManyAsync to just not retry and go through, instead of erroring when used. Any ideas?
Welcome to the MongoDB Community Forums! That does not sound right. Both deleteMany and deleteManyAsync still go through even if retryWrites=true is set. This does not look like a MongoDB issue. Hope that helps.
Hi @Rishit_Bhatia
I am using deleteMany() in the code with retrywrites=false . I get the below
Exception Message: ‘A write operation resulted in an error. WriteError: { Category : “Uncategorized”, Code : 72, Message : “Cannot use (or request) retryable writes with limit=0” }.’
Hi @alexbevi
I am using deleteMany to delete the documents present. I am not sure what do you exactly need.
Here is the line of code - collection.DeleteMany(filter_id);
Unfortunately, I’m not able to reproduce this error. I’m using MongoDB Community 3.6.0 with the C# driver 2.23.1 as you mentioned. The retryWrites option is set in my connection string as follows:
The query used to perform the deleteManyAsync operation looks like this:
var filter = Builders<Restaurant>.Filter.Eq(r => r.Cuisine, "Brazilian");
var result = await _restaurantsCollection.Find(filter).ToListAsync();
Console.WriteLine("Trying to Delete " + result.Count + " Restaurants");
return await _restaurantsCollection.DeleteManyAsync(filter);
Not sure if that helps but if there’s any more information you can share or a sample zip file containing sample code to reproduce this, we’d be happy to take a look at it.
I found the issue for me, it was a cosmosdb thing. You can only use DeleteMany with retryable writes enabled, as long as the filter has the partition key.
I think the error message from MongoDb driver is a little misleading then, or at least, not clear what the issue is.
Since the MongoDB driver wasn’t designed with CosmosDB in mind the failure conditions within that environment would be unpredictable, and may surface in (potentially confusing) ways such as this.