Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
577 stars 836 forks source link

Can the DocumentDB and MongoDB SDKs be used interchangeably? #559

Closed dgioulakis closed 5 years ago

dgioulakis commented 6 years ago

My current understanding of CosmosDB is that the underlying persistence model and/or mechanisms of query "sometimes" vary across data stores.

I'm finding a lot of confusion across StackOverflow and MSDN documentation on the shared functionality of CosmosDB's multi-model support. For instance, MS documentation keeps stating that you choose one client API for your container.

Testing in the emulator, I'm able to create a database and collection using mongo db. Yet I can still interact with it using DocumentDB. (this is testing with the VS-Code CosmosDB Extension)

  1. a) Do all current Cosmos Document databases (DocumentDB & MongoDB) use the same underlying persistence store? b) Can I use the client API's interchangeably if I want? e.g. if I create collection indexes with DocumentDB will Mongo's driver use them? Does index creation from Mongo driver differ than DocDB? c) If so, is it guaranteed that future support for Mongo's protocol won't introduce breaking schema changes that affect DocumentDB's query-ability to my data? If not it seems I truly have to pick just one; it seems there should be complete isolation of data to prevent misuse if this is the case.
  2. I've read that Cosmos' Graph database and Documents can also shared?
  3. What is not supported in shared scenarios? Azure funcs, triggers, stored procs?
  4. Are there any MSDN docs that really outline the boundaries Cosmos imposes upon clients from accessing shared data?

Resources: https://docs.microsoft.com/en-us/azure/cosmos-db/introduction https://stackoverflow.com/questions/44304947/what-does-it-mean-that-azure-cosmos-db-is-multi-model https://github.com/MicrosoftDocs/azure-docs/issues/5460

dgioulakis commented 6 years ago

In further testing using the VSCode-Cosmodb extension it seems these client SDKs are in fact, not interchangeable. Resource identity is alone a contributing factor and I imagine the underlying schemas differ drastically the more I were to use them. e.g. id (documentdb) vs _id (mongo).

I don't think this is the vscode extension issue. It does surprise me that I can see the same databases and collections using two different SDKs. Creating db's and collections doesn't seem to be isolated per-client-sdk. However, records are only (lack of a better term) stable - retrievable and mutable, using the client with which they are created.

UPDATE: 1 I'm now unsure. It seems both work so long as your document has mirrored id and _id field. Creating a new document using either SDK will create the same cosmosdb meta fields: _self, _etag, _rid, _attachments, _ts.