Module spring.data.mongodb
Annotation Interface WildcardIndexed
Annotation for an entity or property that should be used as key for a
Wildcard Index.
If placed on a
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 ElementsModifier and TypeOptional ElementDescriptionDefines the collation to apply.Index name either as plain value or astemplate expression.Only index the documents in a collection that meet a specifiedfilter expression.booleanIf 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 aprasableString.
-
Element Details
-
name
String nameIndex name either as plain value or astemplate 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 useGeneratedNameIf 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 partialFilterOnly index the documents in a collection that meet a specifiedfilter expression.- Returns:
- empty by default.
- See Also:
- Default:
- ""
-
wildcardProjection
String wildcardProjectionExplicitly specify sub fields to be in-/excluded as aprasableString.
NOTE: Can only be applied on root level documents.- Returns:
- empty by default.
- Default:
- ""
-
collation
Defines the collation to apply.- Returns:
- an empty
Stringby default.
- Default:
- ""
-