'Add older documents to stream - based on filter

I created a MongoDB watcher to create actions based on the created document. Of course, the watcher does not detect documents that are created while the service itself is not running.

The current code is only detecting newly created documents. How can I fetch and add older documents to the pipeline based on a field state e.g.: actionDone : true/false.

    var pipeline =
     new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>()
     .Match(x => x.OperationType == ChangeStreamOperationType.Insert);

    using (var cursor = collection.Watch(pipeline))
    {
        foreach (var change in cursor.ToEnumerable())
        {
            string mongoID = change.FullDocument.GetValue("_id").ToString();
        }
    }

Is StartAtOperationTime a option? Didnt find any good documentation here.

Update:

StartAtOperationTime was the solution I was looking for. If anybody is having the same problem, here my solution.

Start to lookup the last 10 days.

   var options = new ChangeStreamOptions
    {
        StartAtOperationTime = new BsonTimestamp(DateTime.Now.AddDays(-10).Ticks)
    };

var cursor = collection.Watch(pipeline,options)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source