C# example is needed for change stream implementation. The JS and C# SDKs don't really line up and it's not obvious how to work with change stream from C#, with the nuances specific to Cosmos DB.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@dmakogon Thanks for the feedback! I have assigned the issue to the content author to evaluate and update as appropriate.
Sent a reminder to the author.
Hello!
I've some questions too. It would be cool if u explained them for me:
Also, I've created a basic example of how to consume "change stream"
var client = new MongoClient(settings);
var database = client.GetDatabase("{database_name}");
var events = database.GetCollection<MongoEvent>("{collection_name}");
var options = new ChangeStreamOptions
{
FullDocument = ChangeStreamFullDocumentOption.UpdateLookup,
};
var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<MongoEvent>>()
.Match(
x => x.OperationType == ChangeStreamOperationType.Insert ||
x.OperationType == ChangeStreamOperationType.Update ||
x.OperationType == ChangeStreamOperationType.Replace)
.Project(
x => new
{
x.ResumeToken,
x.FullDocument,
x.CollectionNamespace,
x.DocumentKey,
})
.ReplaceRoot(x => x.FullDocument);
var cursor = await events.WatchAsync(pipeline, options);
while (await cursor.MoveNextAsync() && !cursor.Current.Any()) {}
var next = cursor.Current.First();
cursor.Dispose();
@srchi Please look into this request from user and help them regarding the same.
@aurokk Hello and thanks for reaching out to us. This feedback mechanism is primarily for communicating about the content of the documents posted on the website. For more general technical questions about cosmosdb, you can reach out to [email protected]. Thanks.
@srchi @hrasheed-msft Any update regarding this. Please let us know if any other information is required.
@NavtejSaini-MSFT @dmakogon The author has reached out to the engineering team, but most people are away for the holidays. Will try to reply with a resolution after Jan 2. Thanks.
@aurokk I'm trying to get your example to work, but I'm getting a "System.InvalidCastException: 'Unable to cast object of type 'MongoDB.Bson.BsonObjectId' to type 'MongoDB.Bson.BsonDocument'.'" when the change stream triggers. Any ideas why? (running the MongoDB.Driver 2.10.0)
Hi all, I've added C# change stream samples. They'll be published later today.