Class ShardKey
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.Document
Get the raw MongoDB representation of theShardKey
.static ShardKey
Create a newShardingStrategy.RANGE
shard key.static ShardKey
boolean
boolean
Return whether the shard key represents a sharded key.static ShardKey
none()
ShardKey
indicating no shard key has been defined.static ShardKey
Create a newShardingStrategy.RANGE
shard key.int
size()
-
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
ShardKey
indicating no shard key has been defined.- Returns:
NONE
-
range
Create a newShardingStrategy.RANGE
shard key.- Parameters:
propertyNames
- must not be null.- Returns:
- new instance of
ShardKey
.
-
hash
Create a newShardingStrategy.RANGE
shard key.- Parameters:
propertyNames
- must not be null.- Returns:
- new instance of
ShardKey
.
-
immutable
- Parameters:
shardKey
- must not be null.- Returns:
- new instance of
ShardKey
if the given shard key is not already immutable.
-