I know I can extract the creationdate from a document from the objectid.
see : When was a document added to a MongoDB collection
I was wondering if there is a similar way to know when a document was updated?
OK, after the comments I received I used this question to create my changestream : How to set MongoDB Change Stream 'OperationType' in the C# driver?
My code looks as follows:
IMongoCollection<RootRecord> collection = db.GetCollection<RootRecord>("companies");
//Get the whole document instead of just the changed portion
ChangeStreamOptions options = new ChangeStreamOptions() { FullDocument = ChangeStreamFullDocumentOption.UpdateLookup };
//The operationType can be one of the following: insert, update, replace, delete, invalidate
var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<RootRecord>>().Match("{ operationType: { $in: [ 'replace', 'insert', 'update' ] } }");
var changeStream = collection.Watch(pipeline, options).ToEnumerable().GetEnumerator();
changeStream.MoveNext(); //Blocks until a document is replaced, inserted or updated in the TestCollection
ChangeStreamDocument<RootRecord> next = changeStream.Current;
changeStream.Dispose();
But this now results in the following exception:
Command aggregate failed: exception: Unrecognized pipeline stage name: '$changeStream'.
What do I need to do to solve this exception?