Is there a way to configure CosmosDB to use the SQL API (DocumentDB) and MongoDB?

When I create a new CosmosDB database in the Azure portal, I have to choose between different APIs (Gremlin, MongoDB, SQL / DocumentDB, and Table.)

As with many other Azure Portal limitations, I hope there is a way to configure the new CosmosDB to use multiple APIs using PowerShell or Azuzre click.

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 using the Mongo api and noticed that Query Explorer is still available and allows me to inject and execute SQL / DocumentDB queries, so apparently both APIs are used by default (Mongo and SQL / DocumentDB). However, I'm not sure 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. Does anyone have any ideas on how to set up a connection string from CosmosDB using the Mongo API so that it is the correct connection string for the DocumentDB / Sql API?

+3


source to share


2 answers


You can use MongoDB API and DocumentDB / Sql API in the same CosmosDB account by doing the following (this probably also works for setting up CosmosDB accounts using Gremlin and Table APIs, but I haven't tried them yet.):

First, create a new CosmosDB account using the MongoDB API. Once this new CosmosDB account is provided, you won't be able to find the Keys blade as you can with a CosmosDB account that has been configured using the DocumentDB / Sql API.

To get the keys required to connect your tenant 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>"

      

You can now use one of these keys in whatever client API (.Net, Python, etc.) you use and make DocumentDB / Sql queries against your CosmosDB, even if it is configured to only use the MongoDB api.

If your client API requires a "Connection String" instead of a simple key, then edit the normal connection string to include that key in the "AccountKey" section of the string.

+5


source


As with many other Azure Portal limitations, I hope there is a way to configure the new CosmosDB to use multiple APIs using PowerShell or Azuzre click.

AFAIK, Azure Cosmos DB currently supports multiple data models (key value, documents, graphs and columns). And each data model has associated APIs for accessing data, including MongoDB , DocumentDB SQL , Gremlin (preview), and Azure Tables (preview).

When creating an Azure Cosmos DB database, you need to select a data model with the appropriate API (your Azure Cosmos DB database type).

How to Create an Azure Cosmos DB account using the Azure CLI , provide the option kind

to create a database account:



The type of Azure Cosmos DB database to create.

Valid 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 know there is no approach for you. Alternatively, you can add your comments here .

+2


source







All Articles