Spring Data MongoDB - Core

org.springframework.data.mongodb.core.index
Annotation Type CompoundIndex


@Target(value=TYPE)
@Documented
@Retention(value=RUNTIME)
public @interface CompoundIndex

Mark a class to use compound indexes.

Author:
Jon Brisbin, Oliver Gierke, Philipp Schneider, Johno Crawford

Optional Element Summary
 boolean background
          If true the index will be created in the background.
 String collection
          The collection the index will be created in.
 String def
          The actual index definition in JSON format.
 IndexDirection direction
          Deprecated. 
 boolean dropDups
           
 int expireAfterSeconds
          Deprecated. TTL cannot be defined for CompoundIndex having more than one field as key. Will be removed in 1.6.
 String name
          The name of the index to be created.
 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.
 

def

public abstract String def
The actual index definition in JSON format. The keys of the JSON document are the fields to be indexed, the values define the index direction (1 for ascending, -1 for descending).
If left empty on nested document, the whole document will be indexed.

Returns:
Default:
""

direction

@Deprecated
public abstract IndexDirection direction
Deprecated. 

It does not actually make sense to use that attribute as the direction has to be defined in the def() attribute actually.

Returns:
Default:
org.springframework.data.mongodb.core.index.IndexDirection.ASCENDING

unique

public abstract boolean unique
Returns:
See Also:
http://docs.mongodb.org/manual/core/index-unique/
Default:
false

sparse

public abstract boolean sparse
If set to true index will skip over any document that is missing the indexed field.

Returns:
See Also:
http://docs.mongodb.org/manual/core/index-sparse/
Default:
false

dropDups

public abstract boolean dropDups
Returns:
See Also:
http://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping
Default:
false

name

public abstract String name
The name of the index to be created.

The name will only be applied as is when defined on root level. For usage on nested or embedded structures the provided name will be prefixed with the path leading to the entity.

The structure below
 
 @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.ensureIndex( { hybrid.h1: 1, hybrid.h2: 1 } , { name: "hybrid.compound_index" } )
 db.root.ensureIndex( { nested.n1: 1, nested.n2: 1 } , { name: "nested.compound_index" } )
 db.hybrid.ensureIndex( { h1: 1, h2: 1 } , { name: "compound_index" } )
 
 

Returns:
Default:
""

useGeneratedName

public abstract boolean useGeneratedName
If set to true then MongoDB will ignore the given index name and instead generate a new name. Defaults to false.

Returns:
Since:
1.5
Default:
false

collection

public abstract String collection
The collection the index will be created in. Will default to the collection the annotated domain class will be stored in.

Returns:
Default:
""

background

public abstract boolean background
If true the index will be created in the background.

Returns:
See Also:
http://docs.mongodb.org/manual/core/indexes/#background-construction
Default:
false

expireAfterSeconds

@Deprecated
public abstract int expireAfterSeconds
Deprecated. TTL cannot be defined for CompoundIndex having more than one field as key. Will be removed in 1.6.

Configures the number of seconds after which the collection should expire. Defaults to -1 for no expiry.

Returns:
See Also:
http://docs.mongodb.org/manual/tutorial/expire-data/
Default:
-1

Spring Data MongoDB - Core

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.