Azure-docs: Missing C# example

Created on 4 Dec 2019  Â·  10Comments  Â·  Source: MicrosoftDocs/azure-docs

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.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 assigned-to-author cosmos-dsvc cosmosdb-mongsubsvc doc-enhancement triaged

All 10 comments

@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:

  1. How to scale "change stream" consumers horizontally?
  2. How to read "change stream" from the start?

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.

please-close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

behnam89 picture behnam89  Â·  3Comments

JeffLoo-ong picture JeffLoo-ong  Â·  3Comments

jebeld17 picture jebeld17  Â·  3Comments

DeepPuddles picture DeepPuddles  Â·  3Comments

monteledwards picture monteledwards  Â·  3Comments