I've seen examples here of people doing this same thing, but for some reason I'm getting an error.
IMongoDatabase db = Globals.gdbSourceDB.GetDatabase(Globals.gsWatchDatabase);
ChangeStreamOptions options = new ChangeStreamOptions() { FullDocument = ChangeStreamFullDocumentOption.UpdateLookup };
var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>().Match("{ operationType: { $in: [ 'replace', 'insert', 'update', 'delete' ] } }");
var changeStream = db.Watch(pipeline, options).ToEnumerable().GetEnumerator();
while (changeStream.MoveNext())
{
ChangeStreamDocument<BsonDocument> next = changeStream.Current;
IMongoDatabase dbDest;
IMongoCollection<BsonDocument> colDest;
dbDest = Globals.gdbDestDB.GetDatabase(Globals.gsWatchDatabase);
colDest = dbDest.GetCollection<BsonDocument>(next.CollectionNamespace.CollectionName);
if (next.OperationType.ToString() == "Delete")
{
//Delete the same record
var retDel = colDest.DeleteOne(a => a.Id == next.DocumentKey);
}
}
I know next.DocumentKey
isn't exactly correct, but the problem is with a.Id. I'm getting the following error:
Error CS1061 'BsonDocument' does not contain a definition for 'Id' and no accessible extension method 'Id' accepting a first argument of type 'BsonDocument' could be found (are you missing a using directive or an assembly reference?)
What am I doing wrong? Thanks!