2
public async Task RealtionalCollectionCollectionChange(CancellationToken cancellationToken)
{
var options = new ChangeStreamOptions
{
FullDocument = ChangeStreamFullDocumentOption.UpdateLookup,
BatchSize = 2
};
var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>().Match("{operationType: { $in: [ 'replace', 'insert', 'update', 'delete' ] } }");
using(var cursor = await collection.WatchAsync(pipeline, options, cancellationToken))
{
while (await cursor.MoveNextAsync(cancellationToken))
{
if (cancellationToken.IsCancellationRequested)
{
break;
}
int mailCounter = 0; // initialize counter variable
foreach(var change in cursor.Current)
{
if (mailCounter < option.BatchSize) // limit number of emails sent
{
// Sending mail code
mailCounter ++; // increment mail count for this batch
}
}
}
}
cursor.Dispose();
}
1
Hi Amit,
It is working for one time i.e., when I delete first batch 5 records it sent 2 mails only, however when I delete second time 5 records, it didn't send any mails as mailcounter is 2.
When I set mailcounter = 0 in else part, first time also it is sending 5 mails.
When I try to dispose cursor it is throwing error.
Not sure how to fix this issue.
Thanks,
Lalitha.C