Search code examples
azure-cosmosdbazure-cosmosdb-mongoapichangestreamazure-cosmosdb-changefeed

Azure Cosmos DB Change Feed with MongoDB API (Not change stream!)


I've been struggling to understand the Azure Cosmos DB official docs.

This link shows that change feed can work with the "MongoDB" : Change feed in Azure Cosmos DB

But the following paragraph is what is confusing me:

enter image description here

So my question is following can Azure Cosmos DB Change Feed work with MongoDB API (Not using change stream!)?

The documentation on this on the web is scarce and I can't find useful information on this subject.

To me it would make sense that change feed is supported since the Mongo API is just a layer over Cosmos DB but nothing would surprise me.

In case change stream is supported but not change feed, is it possible to define the oplog retention time or size, if not what are the defaults? (Again almost impossible information to find on the internet).


Solution

  • can Azure Cosmos DB Change Feed work with MongoDB API (Not using change stream!)

    Basically no.

    It used to be at least unofficially possible by connecting to the SQL API endpoint but this is now blocked or unavailable on newly created Mongo accounts.

    The documents surfaced when using the change feed via that route were the SQL API representations of BSON documents though and I don't think deserializing that was ever at all documented or supported.

    It is unfortunate that this route has been closed off however because there is no replacement functionality provided out the box for using the CosmosDB "ChangeStreams" as a trigger source for an Azure function and parallelising across physical partitions (even though technically it could be implemented very similarly after calling "GetChangeStreamTokens").

    My understanding is that change streams is just the Mongo API interface for exposing change feed though so it is basically implemented exactly the same way and has the same limitations. i.e. it has no separate oplog as it has no record of change history. It is just traversing the documents within a partition in order of LSN.

    And because change feed does not currently expose deletes or guarantee all document versions (in the case that a document is written multiple times) neither can change streams - which is why it is required to specify $in: ["insert", "update", "replace"]).