【问题标题】:Azure CosmosDB emulator errors "query in command must target a single shard key"Azure CosmosDB 模拟器错误“命令中的查询必须针对单个分片键”
【发布时间】:2020-10-16 17:44:10
【问题描述】:

在使用自定义分片键时,我需要帮助以使模拟器的行为与 cosmos DB 相同。在调用以下 golang mongo 驱动程序 API 时,模拟器期望分片键位于 filter 参数中。否则,它将返回错误代码 61,并显示消息“命令中的查询必须针对单个分片键”

func (c *collection) replaceDocument(ctx context.Context, filter Filter, doc Document, upsert bool) (bool, error) {

相同的代码在 Azure cosmos DB 上运行正常。下面是我使用的文档架构。我仅在调用上述 API 时过滤唯一的_id

{
   "_id": ==> unique non NULL key,
   "shard_key": ==> non NULL string field for sharding,
   other fields,
}

【问题讨论】:

    标签: azure-cosmosdb-mongoapi azure-cosmosdb-emulator


    【解决方案1】:

    CosmosDB 模拟器提供了在本地工作站上运行的 CosmosDB 服务的模拟。这可能会导致模拟器行为与服务帐户行为之间存在差异。更多信息可以阅读here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多