.. _sharding: Sharding ======== MongoDB allows you to horizontally scale your database. In order to enable this, Doctrine MongoDB ODM needs to know about your sharding setup. For basic information about sharding, please refer to the `MongoDB docs `_. Once you have a `sharded cluster `_, you can enable sharding for a document. You can do this by defining a shard key in the document: .. configuration-block:: .. code-block:: php .. code-block:: yaml Documents\User: shardKey: keys: username: asc .. note:: When a shard key is defined for a document, Doctrine MongoDB ODM will no longer persist changes to the shard key as these fields become immutable in a sharded setup. Once you've defined a shard key you need to enable sharding for the collection where the document will be stored. To do this, use the ``odm:schema:shard`` command. .. note:: For performance reasons, sharding is not enabled during the ``odm:schema:create`` and ``odm:schema:update`` commmands.