Cosmos Db Change Feed do not give the desired result

Ankit Kumar 91 Reputation points
2020-12-01T14:46:57.713+00:00

I am trying to get all the changes from my monitored Db in the Cosmos db Change Feed by following the below codes. I am trying for different duration like the changes happening today or the changes happened in last 7 days or changes happened overall. Now in all the cases I get all the changes in first time and no changes in the second run unless there is a change coming. I would like to know what wrong am I doing here, and If I have to get changes for only last week on my each run, How should I configure the change feed if my below code is not correct. Thanks in Advance.

private static CosmosClient Client { get; set; }
    static void Main(string[] args)
    {
        Task.Run(async () =>
        {
            Client = new CosmosClient("AccountEndpoint = https://test.documents.azure.com:443/;AccountKey=FW5yvDA==;");
            var database = Client.GetDatabase("twstDatabase");
            var container = database.GetContainer("TestContainer");
            var leaseContainer = database.GetContainer("leases");

            var cfp = container.GetChangeFeedProcessorBuilder<dynamic>("cfpLibraryDThird", ProcessChanges)
                .WithLeaseContainer(leaseContainer)
                .WithInstanceName("Change Feed Instance Demo") 
// I change the instance name for different start time
                    .WithStartTime(DateTime.Today.AddDays(-7).ToUniversalTime())
                    //.WithStartTime(DateTime.MinValue.ToUniversalTime())
                    .Build();
                await cfp.StartAsync();
                Console.WriteLine("Started Change feed processor- press key to stop");
                Console.ReadKey(true);
                await cfp.StopAsync();
            }).Wait();
        }

        static async Task ProcessChanges(IReadOnlyCollection<dynamic> docs, CancellationToken cancellationToken)
        {
            foreach (var doc in docs)
            {
                Console.WriteLine($"Document {doc.id} has changed");

            }
        }
    }
}
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,659 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anurag Sharma 17,606 Reputation points
    2020-12-02T18:00:55.167+00:00

    Hi @Ankit Kumar , welcome to Microsoft Q&A.

    We just noticed that you had posted the similar query on GitHub forum and it mentioned that its bug with .NET SDK 3.15 and will work with earlier version.

    Posting it here again for broader audience.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.