org.springframework.data.mongodb.core.index

Annotation Type CompoundIndex

    • Optional Element Summary

      Optional Elements 
      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.
      IndexDirection direction
      Deprecated. 
      boolean dropDups
      Deprecated. 
      since 2.1. No longer supported by MongoDB as of server version 3.0.
      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.
    • Element Detail

      • 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
      • 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.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" } )
         
         
        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