@Target(value=TYPE) @Documented @Repeatable(value=CompoundIndexes.class) @Retention(value=RUNTIME) public @interface CompoundIndex
NOTE: This annotation is repeatable according to Java 8 conventions using CompoundIndexes.value()
as
container.
@Document @CompoundIndex(def = "{'firstname': 1, 'lastname': 1}") @CompoundIndex(def = "{'address.city': 1, 'address.street': 1}") class Person { String firstname; String lastname; Address address; }
Modifier and Type | Optional Element and Description |
---|---|
boolean |
background
If true the index will be created in the background.
|
String |
def
The actual index definition in JSON format or a
template expression resolving to either a JSON String or a Document . |
IndexDirection |
direction
Deprecated.
|
boolean |
dropDups
Deprecated.
since 2.1. No longer supported by MongoDB as of server version 3.0.
|
String |
name
Index name of the index to be created 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 |
boolean |
useGeneratedName
If set to true then MongoDB will ignore the given index name and instead generate a new name.
|
public abstract String def
template expression
resolving to either a JSON String or a Document
. The keys of the JSON
document are the fields to be indexed, the values define the index direction (1 for ascending, -1 for descending).
@Document @CompoundIndex(def = "{'h1': 1, 'h2': 1}") class JsonStringIndexDefinition { String h1, h2; } @Document @CompoundIndex(def = "#{T(org.bson.Document).parse("{ 'h1': 1, 'h2': 1 }")}") class ExpressionIndexDefinition { String h1, h2; }
@Deprecated public abstract IndexDirection direction
def()
attribute actually.IndexDirection.ASCENDING
by default.public abstract boolean unique
public abstract boolean sparse
partialFilter()
.@Deprecated public abstract boolean dropDups
public abstract String name
template expression
. @Document class Root { Hybrid hybrid; Nested nested; } @Document @CompoundIndex(name = "compound_index", def = "{'h1': 1, 'h2': 1}") class Hybrid { String h1, h2; } @CompoundIndex(name = "compound_index", def = "{'n1': 1, 'n2': 1}") class Nested { String n1, n2; }resolves in the following index structures
db.root.createIndex( { hybrid.h1: 1, hybrid.h2: 1 } , { name: "hybrid.compound_index" } ) db.root.createIndex( { nested.n1: 1, nested.n2: 1 } , { name: "nested.compound_index" } ) db.hybrid.createIndex( { h1: 1, h2: 1 } , { name: "compound_index" } )
public abstract boolean useGeneratedName
public abstract boolean background
public abstract String partialFilter
filter expression
. sparse = true
.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.