The index used for a shard key cannot be a multikey.
Hence inserts into a sharded collection that would turn the relevant index into a multi-key index are prevented, but only if the index is identical with the shard key:
If the shard key is instead only a prefix of the index, we do not prevent such inserts for other fields. This causes the index to turn into a multikey index and splitVectors will fail.
- Set up sharded cluster
- Connect to mongos, insert a document into a collection:
- Create index on all 4 fields:
- Enable sharding and shard collection on a prefix of the index:
- Now insert a document that contains an array for c:
- Switch to mongod and run a splitVector command
Any insert turning the index into a multikey index should fail with an error, as it does when the index pattern is identical to the shard key.