0

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

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

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

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

1 回答 1

0

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

于 2020-10-24T23:24:02.580 回答