有没有办法将 CosmosDB 配置为同时使用 SQL (DocumentDB) 和 MongoDB API?

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

当我在 Azure 门户中创建新的 CosmosDB 数据库时,我必须在各种 API 之间进行选择(Gremlin、MongoDB、SQL/DocumentDB 和 Table.)

与 Azure 门户的许多其他限制一样,我希望有一种方法可以使用 PowerShell 或 Azuzre cli 配置新的 CosmosDB 以使用多个 APIs。

有没有办法向我的 CosmosDB 实例添加额外的 API?如果没有,以后有办法吗?

更新: 我刚刚使用 Mongo api 创建了一个 Cosmos DB 帐户,并注意到查询资源管理器仍然可用,并允许我输入并执行 SQL/DocumentDB 查询,显然默认是允许 APIs(Mongo 和 SQL/DocumentDB)。但是,我不确定如何获取 ConnectionString (AccountKey),以便我可以像 Azure 门户在我自己的客户端中那样使用 DocumentDB/SQL API。任何人都知道如何使用 Mongo API 从 CosmosDB 设置连接字符串,以便它是 DocumentDB/Sql API?[=12= 的有效连接字符串]

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.

据我所知,Azure Cosmos DB 目前支持多种数据模型(键值、文档、图形和柱状)。每个数据模型都有相关的 APIs 用于访问数据,包括 MongoDB, DocumentDB SQL, Gremlin (preview), and Azure Tables(预览)。

创建Azure Cosmos DB数据库账户时,需要选择与API(你的Azure Cosmos DB数据库账户类型)相关的数据模型。

正如 Create an Azure Cosmos DB account using the Azure CLI 关于创建数据库帐户的 kind 参数所述:

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?

据我所知,您没有实现它的方法。此外,您可以添加您的反馈 here.

您可以通过执行以下操作在同一个 CosmosDB 帐户中同时使用 MongoDB API 和 DocumentDB/Sql API(这可能也适用于 CosmosDB 帐户设置使用 Gremlin 和 Table APIs,但我还没有尝试过。):

首先,使用 MongoDB API 创建一个新的 CosmosDB 帐户。一旦配置了这个新的 CosmosDB 帐户,您将无法找到 "Keys" blade,就像使用已配置 DocumentDB/Sql API 的 CosmosDB 帐户一样.

要获取将客户端连接到 DocumentDB/Sql api、运行 以下 Azure CLI Command:

所需的密钥
az cosmosdb list-keys --name "<your cosmosdb account name>" --resource-group "<name of resource group your cosmosdb lives in>"

现在,您可以在您正在使用的任何客户端 API(.Net、Python 等)中使用这些密钥之一,并对您的 DocumentDB/Sql 查询CosmosDB 即使它仅配置为使用 MongoDB api.

如果您的客户端 API 需要 "Connection String" 而不仅仅是密钥,则编辑普通连接字符串以将此密钥包含在字符串的 "AccountKey" 部分中。

这里的答案不再有效,否。虽然这在技术上可能是可行的。您必须坚持创建数据库时选择的那个。

唯一可能的组合是 Gremlin 和 SQL API。从这里阅读

https://docs.microsoft.com/en-us/azure/cosmos-db/faq#can-i-use-multiple-apis-to-access-my-data