Annotation Interface Indexed


@Target({ANNOTATION_TYPE,FIELD}) @Retention(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, Christoph Strobl, Jordi Llach, Mark Paluch, Stefan Tirea
  • Element Details

    • unique

      boolean unique
      If set to true reject all documents that contain a duplicate value for the indexed field.
      Returns:
      false by default.
      See Also:
      Default:
      false
    • direction

      IndexDirection direction
      The index sort direction.
      Returns:
      IndexDirection.ASCENDING by default.
      Default:
      ASCENDING
    • sparse

      boolean sparse
      If set to true index will skip over any document that is missing the indexed field.
      Must not be used with partialFilter().
      Returns:
      false by default.
      See Also:
      Default:
      false
    • name

      String name
      Index name either as plain value or as template expression.

      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;
         @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 } )
       
       
      Returns:
      empty String by default.
      Default:
      ""
    • useGeneratedName

      boolean useGeneratedName
      If set to true then MongoDB will ignore the given index name and instead generate a new name. Defaults to false.
      Returns:
      false by default.
      Since:
      1.5
      Default:
      false
    • background

      boolean background
      If true the index will be created in the background.
      Returns:
      false by default.
      See Also:
      Default:
      false
    • expireAfterSeconds

      @Deprecated(since="4.4", forRemoval=true) int expireAfterSeconds
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 4.4 - Please use expireAfter() instead.
      Configures the number of seconds after which the collection should expire. Defaults to -1 for no expiry.
      Returns:
      -1 by default.
      See Also:
      Default:
      -1
    • expireAfter

      String expireAfter
      Alternative for 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:
      • d: Days
      • h: Hours
      • m: Minutes
      • s: Seconds
      • Alternatively: A Spring template expression. The expression can result in a Duration or a valid expiration String according to the already mentioned conventions.
      Supports ISO-8601 style.
       @Indexed(expireAfter = "10s") String expireAfterTenSeconds;
       @Indexed(expireAfter = "1d") String expireAfterOneDay;
       @Indexed(expireAfter = "P2D") String expireAfterTwoDays;
       @Indexed(expireAfter = "#{@mySpringBean.timeout}") String expireAfterTimeoutObtainedFromSpringBean;
       
      Returns:
      empty by default.
      Since:
      2.2
      Default:
      ""
    • partialFilter

      String partialFilter
      Only index the documents in a collection that meet a specified filter expression.
      Must not be used with sparse = true.
      Returns:
      empty by default.
      Since:
      3.1
      See Also:
      Default:
      ""
    • collation

      The actual collation definition in JSON format or a template expression resolving to either a JSON String or a Document. The keys of the JSON document are configuration options for the collation (language-specific rules for string comparison) applied to the indexed based on the field value.

      NOTE: Overrides Document.collation().

      Returns:
      empty by default.
      Since:
      4.0
      See Also:
      Default:
      ""