Index

Basically encapsulated common mongodb index.

Firstly create a MongoIndex object.

MongoIndex index=new MongoIndex(collection name needed to operate);

Searching index

index.get();

Adding index(Notice: the format of field name is “collection name. field name” such as map.position)

index //Append method after index
.ascending(FieldName...) //Positive index
.descending(FieldName...) //Invert index
.geo2dsphere(FieldName...)
.geo2d(FieldName...)
.geoHaystack(FieldName..,bson)
.text(FieldName)
.hashed(FieldName)
.setUnique(FieldName) //Unique index
.setBackground(boolean) //Whether to run in background
.setSparse(FieldName) //Sparse index
.save(); //Must be “save()”  at last

Composite index

index.add(new MongoIndex() /*Add the index mentioned in [add index], but do not add save*/).compound();

Deletion index

Just “save” convert to “delete”. “index.deleteAll ()” to delete all.

results matching ""

    No results matching ""