@Target(value={ANNOTATION_TYPE,FIELD}) @Retention(value=RUNTIME) public @interface Indexed
Modifier and Type | Optional Element and Description |
---|---|
boolean |
background
If true the index will be created in the background.
|
IndexDirection |
direction
The index sort direction.
|
boolean |
dropDups
Deprecated.
since 2.1. No longer supported by MongoDB as of server version 3.0.
|
String |
expireAfter
Alternative for
expireAfterSeconds() to configure the timeout after which the document should expire. |
int |
expireAfterSeconds
Configures the number of seconds after which the collection should expire.
|
String |
name
Index name either as plain value or as
template
expression . |
String |
partialFilter
Only index the documents in a collection that meet a specified
filter expression . |
boolean |
sparse
If set to true index will skip over any document that is missing the indexed field.
|
boolean |
unique
If set to true reject all documents that contain a duplicate value for the indexed field.
|
boolean |
useGeneratedName
If set to true then MongoDB will ignore the given index name and instead generate a new name.
|
public abstract boolean unique
public abstract IndexDirection direction
IndexDirection.ASCENDING
by default.public abstract boolean sparse
partialFilter()
.@Deprecated public abstract boolean dropDups
public abstract String name
template
expression
.
@Document
class Root {
Hybrid hybrid;
Nested nested;
}
@Document
class Hybrid {
@Indexed(name="index") String h1;
@Indexed(name="#{@myBean.indexName}") String h2;
}
class Nested {
@Indexed(name="index") String n1;
}
resolves in the following index structures
db.root.createIndex( { hybrid.h1: 1 } , { name: "hybrid.index" } )
db.root.createIndex( { nested.n1: 1 } , { name: "nested.index" } )
db.hybrid.createIndex( { h1: 1} , { name: "index" } )
db.hybrid.createIndex( { h2: 1} , { name: the value myBean.getIndexName() returned } )
public abstract boolean useGeneratedName
public abstract boolean background
public abstract int expireAfterSeconds
public abstract String expireAfter
expireAfterSeconds()
to configure the timeout after which the document should expire.
Defaults to an empty String
for no expiry. Accepts numeric values followed by their unit of measure:
Duration
or a valid expiration String
according to the already mentioned
conventions.@Indexed(expireAfter = "10s") String expireAfterTenSeconds; @Indexed(expireAfter = "1d") String expireAfterOneDay; @Indexed(expireAfter = "P2D") String expireAfterTwoDays; @Indexed(expireAfter = "#{@mySpringBean.timeout}") String expireAfterTimeoutObtainedFromSpringBean;
public abstract String partialFilter
filter expression
. sparse = true
.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.