java.lang.Object
org.springframework.data.mongodb.core.mapping.ShardKey
Value object representing an entities Shard
Key used to distribute documents across a sharded MongoDB cluster.
Immutable shard keys indicates a fixed value that is not updated (see
MongoDB
Reference: Change a Document's Shard Key Value), which allows to skip server round trips in cases where a
potential shard key change might have occurred.- Since:
- 3.0
- Author:
- Christoph Strobl, Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionorg.bson.DocumentGet the raw MongoDB representation of theShardKey.static ShardKeyCreate a newShardingStrategy.RANGEshard key.static ShardKeybooleanbooleanReturn whether the shard key represents a sharded key.static ShardKeynone()ShardKeyindicating no shard key has been defined.static ShardKeyCreate a newShardingStrategy.RANGEshard key.intsize()
-
Method Details
-
size
public int size()- Returns:
- the number of properties used to form the shard key.
-
getPropertyNames
- Returns:
- the unmodifiable collection of property names forming the shard key.
-
isImmutable
public boolean isImmutable()- Returns:
- true if the shard key of an document does not change.
- See Also:
-
isSharded
public boolean isSharded()Return whether the shard key represents a sharded key. Return false if the key is not sharded.- Returns:
- true if the key is sharded; false otherwise.
-
getDocument
public org.bson.Document getDocument()Get the raw MongoDB representation of theShardKey.- Returns:
- never null.
-
none
ShardKeyindicating no shard key has been defined.- Returns:
NONE
-
range
Create a newShardingStrategy.RANGEshard key.- Parameters:
propertyNames- must not be null.- Returns:
- new instance of
ShardKey.
-
hash
Create a newShardingStrategy.RANGEshard key.- Parameters:
propertyNames- must not be null.- Returns:
- new instance of
ShardKey.
-
immutable
- Parameters:
shardKey- must not be null.- Returns:
- new instance of
ShardKeyif the given shard key is not already immutable.
-