Module spring.data.mongodb
Annotation Interface Sharded
The
Please see the MongoDB Documentation for more information about requirements and limitations of sharding.
Spring Data adds the shard key to filter queries used for
All other operations that require the presence of the shard key in the filter query need to provide the information via the
Sharded annotation provides meta information about the actual distribution of data. The
shardKey() is used to distribute documents across shards. Please see the MongoDB Documentation for more information about requirements and limitations of sharding.
Spring Data adds the shard key to filter queries used for
MongoCollection.replaceOne(org.bson.conversions.Bson, Object) operations triggered by
save operations on MongoOperations and
ReactiveMongoOperations as well as update/upsert operations
replacing/upserting a single existing document as long as the given
UpdateDefinition holds a full copy of the entity.
All other operations that require the presence of the shard key in the filter query need to provide the information via the
Query parameter when invoking the method.- Since:
- 3.0
- Author:
- Christoph Strobl, Mark Paluch
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanAs of MongoDB 4.2 it is possible to change the shard key using update.The sharding strategy to use for distributing data across sharded clusters.String[]The shard key determines the distribution of the collection's documents among the cluster's shards.String[]Alias forshardKey().
-
Element Details
-
value
Alias forshardKey().- Returns:
- _id by default.
- See Also:
- Default:
- {}
-
shardKey
The shard key determines the distribution of the collection's documents among the cluster's shards. The shard key is either a single or multiple indexed properties that exist in every document in the collection.
By default the id property is used for sharding.
NOTE: Required indexes are not created automatically. Create these either externally, viaIndexOperations.ensureIndex(org.springframework.data.mongodb.core.index.IndexDefinition)or by annotating your domain model withIndexed/CompoundIndexalong with enabledauto index creation.- Returns:
- an empty key by default. Which indicates to use the entities id property.
- Default:
- {}
-
shardingStrategy
ShardingStrategy shardingStrategyThe sharding strategy to use for distributing data across sharded clusters.- Returns:
ShardingStrategy.RANGEby default
- Default:
- RANGE
-
immutableKey
boolean immutableKeyAs of MongoDB 4.2 it is possible to change the shard key using update. Using immutable shard keys avoids server round trips to obtain an entities actual shard key from the database.- Returns:
- false by default.
- See Also:
- Default:
- false
-