Annotation Interface WildcardIndexed


@Documented @Target({TYPE,FIELD}) @Retention(RUNTIME) public @interface WildcardIndexed
Annotation for an entity or property that should be used as key for a Wildcard Index.
If placed on a type that is a root level domain entity (one having an Document annotation) will advise the index creator to create a wildcard index for it.

 @Document
 @WildcardIndexed
 public class Product {
     ...
 }

 db.product.createIndex({ "$**" : 1 } , {})
 
wildcardProjection can be used to specify keys to in-/exclude in the index.

 @Document
 @WildcardIndexed(wildcardProjection = "{ 'userMetadata.age' : 0 }")
 public class User {
     private @Id String id;
     private UserMetadata userMetadata;
 }


 db.user.createIndex(
   { "$**" : 1 },
   { "wildcardProjection" :
     { "userMetadata.age" : 0 }
   }
 )
 
Wildcard indexes can also be expressed by adding the annotation directly to the field. Please note that wildcardProjection is not allowed on nested paths.
 @Document
 public class User {

     private @Id String id;

     @WildcardIndexed
     private UserMetadata userMetadata;
 }


 db.user.createIndex({ "userMetadata.$**" : 1 }, {})
 
Since:
3.3
Author:
Christoph Strobl
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Defines the collation to apply.
    Index name either as plain value or as template expression.
    Only index the documents in a collection that meet a specified filter expression.
    boolean
    If set to true then MongoDB will ignore the given index name and instead generate a new name.
    Explicitly specify sub fields to be in-/excluded as a prasable String.
  • Element Details

    • 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.
      Returns:
      empty 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.
      Default:
      false
    • partialFilter

      String partialFilter
      Only index the documents in a collection that meet a specified filter expression.
      Returns:
      empty by default.
      See Also:
      Default:
      ""
    • wildcardProjection

      String wildcardProjection
      Explicitly specify sub fields to be in-/excluded as a prasable String.
      NOTE: Can only be applied on root level documents.
      Returns:
      empty by default.
      Default:
      ""
    • collation

      @AliasFor(annotation=Collation.class, attribute="value") String collation
      Defines the collation to apply.
      Returns:
      an empty String by default.
      Default:
      ""