When I create a new CosmosDB database in the Azure Portal, I have to choose between the various APIs (Gremlin, MongoDB, SQL/DocumentDB, and Table.)
As with soo many other limitations of the Azure Portal, I'm hoping that there is a way to configure the new CosmosDB to use multiple APIs using PowerShell or the Azuzre cli.
Is there a way to add additional APIs to my CosmosDB instance? If not, will there be a way to do this in the future?
Update: I just created a Cosmos DB Account with the Mongo api, and noticed that the Query Explorer is still available, and allows me to type in and execute SQL/DocumentDB queries, so apparently the default is to allow both APIs (Mongo and SQL/DocumentDB). However, I'm not sure of how to get the ConnectionString (AccountKey) so that I can use the DocumentDB/SQL API the way the azure portal does in my own client. Anyone have ideas on how to setup the connection string from a CosmosDB using the Mongo API so that it is a valid connection string for the DocumentDB/Sql API?
You can use both the MongoDB API and the DocumentDB/Sql API in the same CosmosDB account by doing the following (this likely also works for CosmosDB accounts setup with Gremlin and Table APIs, but I haven't yet tried them yet.):
First, create a new CosmosDB account using the MongoDB API. Once this new CosmosDB account is provisioned, you won't be able to find the "Keys" blade as you can with a CosmosDB account that has been configured with the DocumentDB/Sql API.
To get the Keys which you need to connect your client to the DocumentDB/Sql api, run the following Azure CLI Command:
az cosmosdb list-keys --name "<your cosmosdb account name>" --resource-group "<name of resource group your cosmosdb lives in>"
Now, you can use one of these keys in whatever client API (.Net, Python, etc.) that you are using, and do DocumentDB/Sql queries against your CosmosDB even though it was only configured to use the MongoDB api.
If your client API requires a "Connection String" instead of just a key, then edit the normal connection string to include this key in the "AccountKey" section of the string.
As with soo many other limitations of the Azure Portal, I'm hoping that there is a way to configure the new CosmosDB to use multiple APIs using PowerShell or the Azuzre cli.
AFAIK, Azure Cosmos DB supports multiple data models (key-value, documents, graphs, and columnar) for now. And each data models have the related APIs for accessing data including MongoDB, DocumentDB SQL, Gremlin (preview), and Azure Tables (preview).
When you creating an Azure Cosmos DB database account, you need to choose the data model with the related API (the type of your Azure Cosmos DB database account).
As Create an Azure Cosmos DB account using the Azure CLI states about the kind
parameter for creating database account:
The type of Azure Cosmos DB database account to create.
Allowed values: GlobalDocumentDB, MongoDB, Parse.
Default: GlobalDocumentDB.
Is there a way to add additional APIs to my CosmosDB instance? If not, will there be a way to do this in the future?
As I known, there is no approach for you to achieve it. Additionally, you could add your feedback here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With