I’m processing thousands of rows using BulkWriteAsync(writeModels) and it runs for a long time and then aborts with “The positional operator did not find the match needed from the query”. My theory is that somehow it’s something wrong a subset of documents (or perhaps the updatedefinition was misconfigured for some docs). However, from a WriteModel object I cannot find any way to serialize it to return the filter and updatedefinition. I have tried .toString(), .toJson(), .toBsonDocument().
How can I serialize them to some nice readable form so I can compare the failing data to the ‘good data’? When I view in VS debugger they seem to hold endless arrays that never show me anything valid.
Instead of applying special logic for this use case, you could consider using logging. MongoDB C# Driver integrates with the .NET (Core) logging framework.
For details, see the documentation here.