在使用自定义分片键时,我需要帮助以使模拟器的行为与 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,
}