Package com.mongodb.client.model
Class Indexes
java.lang.Object
com.mongodb.client.model.Indexes
A factory for defining index keys. A convenient way to use this class is to statically import all of its methods, which allows usage
like:
collection.createIndex(compoundIndex(ascending("x"), descending("y")));
- Since:
- 3.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic Bson
Create an index key for an ascending index on the given fields.static Bson
Create an index key for an ascending index on the given fields.static Bson
compoundIndex
(List<? extends Bson> indexes) compound multiple index specifications.static Bson
compoundIndex
(Bson... indexes) create a compound index specifications.static Bson
descending
(String... fieldNames) Create an index key for an descending index on the given fields.static Bson
descending
(List<String> fieldNames) Create an index key for an descending index on the given fields.static Bson
Create an index key for a 2d index on the given field.static Bson
geo2dsphere
(String... fieldNames) Create an index key for an 2dsphere index on the given fields.static Bson
geo2dsphere
(List<String> fieldNames) Create an index key for an 2dsphere index on the given fields.static Bson
Create an index key for a hashed index on the given field.static Bson
text()
Create an index key for a text index on every field that contains string data.static Bson
Create an index key for a text index on the given field.
-
Method Details
-
ascending
Create an index key for an ascending index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- indexes
-
ascending
Create an index key for an ascending index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- indexes
-
descending
Create an index key for an descending index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- indexes
-
descending
Create an index key for an descending index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- indexes
-
geo2dsphere
Create an index key for an 2dsphere index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- 2dsphere Index
-
geo2dsphere
Create an index key for an 2dsphere index on the given fields.- Parameters:
fieldNames
- the field names, which must contain at least one- Returns:
- the index specification
- MongoDB documentation
- indexes
-
geo2d
Create an index key for a 2d index on the given field.Note: A 2d index is for data stored as points on a two-dimensional plane. The 2d index is intended for legacy coordinate pairs used in MongoDB 2.2 and earlier.
- Parameters:
fieldName
- the field to create a 2d index on- Returns:
- the index specification
- MongoDB documentation
- 2d index
-
text
Create an index key for a text index on the given field.- Parameters:
fieldName
- the field to create a text index on- Returns:
- the index specification
- MongoDB documentation
- text index
-
text
Create an index key for a text index on every field that contains string data.- Returns:
- the index specification
- MongoDB documentation
- text index
-
hashed
Create an index key for a hashed index on the given field.- Parameters:
fieldName
- the field to create a hashed index on- Returns:
- the index specification
- MongoDB documentation
- hashed index
-
compoundIndex
create a compound index specifications. If any field names are repeated, the last one takes precedence.- Parameters:
indexes
- the index specifications- Returns:
- the compound index specification
- MongoDB documentation
- compoundIndex
-
compoundIndex
compound multiple index specifications. If any field names are repeated, the last one takes precedence.- Parameters:
indexes
- the index specifications- Returns:
- the compound index specification
- MongoDB documentation
- compoundIndex
-