Spring Data MongoDB - Core

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


@Target(value=FIELD)
@Retention(value=RUNTIME)
public @interface Indexed

Mark a field to be indexed using MongoDB's indexing feature.

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

Optional Element Summary
 boolean background
          If true the index will be created in the background.
 String collection
          Colleciton name for index to be created on.
 IndexDirection direction
           
 boolean dropDups
           
 int expireAfterSeconds
          Configures the number of seconds after which the collection should expire.
 String name
          Index name.
 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.
 

unique

public abstract boolean unique
If set to true reject all documents that contain a duplicate value for the indexed field.

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

direction

public abstract IndexDirection direction
Default:
org.springframework.data.mongodb.core.index.IndexDirection.ASCENDING

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
Index name.

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
 class Hybrid {
   @Indexed(name="index") String h1;
 }
 
 class Nested {
   @Indexed(name="index") String n1;
 }
 
 
resolves in the following index structures
 
 db.root.ensureIndex( { hybrid.h1: 1 } , { name: "hybrid.index" } )
 db.root.ensureIndex( { nested.n1: 1 } , { name: "nested.index" } )
 db.hybrid.ensureIndex( { h1: 1} , { name: "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
Colleciton name for index to be created on.

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

public abstract int expireAfterSeconds
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.