分片集合和 MongoDb

Sharded collections and MongoDb

我已经通过门户在 Cosmos 上创建了一个分片集合(用于 C# MongoDB 驱动程序)。使用 Data Explorer -> New Collection 创建 - 此时设置 Shard Key。

我已经将分片键设置为 partitionId

作为尝试将此文档插入名为 "data" 的集合的示例:

db.data.insert({partitionId:"test"})

我收到错误 Command insert failed: document does not contain shard key.

编辑:

使用门户创建分片集合时似乎存在问题。手动创建分片集合应该可行,请参阅:

原文:

来自the docs

The shard key determines the distribution of the collection’s documents among the cluster’s shards. The shard key is either an indexed field or indexed compound fields that exists in every document in the collection.

在创建分片集合时,您提供了一个应该用作分片键的键。接下来,如果您插入一个文档,它必须包含该键。参见 here