想象我们有这样的文件:
{
_id: ObjectId(""),
accountId: ObjectId(""),
userId: ObjectId(""),
someOtherFieldA: ["some", "array", "values"],
someOtherFieldB: ["other", "array", "values"],
...
}
此外,还有多个复合索引,例如:
{ userId: 1, someOtherFieldA: 1, ... }
{ userId: 1, someOtherFieldB: 1, ... }
我们想按accountId
分片。
为accountId
添加单个字段索引是否足够,以便现有索引仍然有效?还是所有索引都需要accountId
作为前缀(第一部分)?
[当您运行sh.shardCollection()
命令时,MongoDB会在分片键字段上自动创建一个索引(除非已经存在这样的索引),因此您不必关心这个问题。