use of com.mongodb.operation.OrderBy in project mongo-java-driver by mongodb.
the class AddIndexAcceptanceTest method shouldSupportCompoundIndexesWithDifferentOrders.
@Test
public void shouldSupportCompoundIndexesWithDifferentOrders() {
collection.createIndex(new Document("theFirstField", 1).append("theSecondField", -1));
Document newIndexDetails = collection.listIndexes().into(new ArrayList<Document>()).get(1);
Document keys = (Document) newIndexDetails.get("key");
OrderBy orderBy = fromInt((Integer) keys.get("theFirstField"));
assertThat("First index should be ascending", orderBy, is(ASC));
orderBy = fromInt((Integer) keys.get("theSecondField"));
assertThat("Second index should be descending", orderBy, is(DESC));
assertThat("Index name should contain both field names", (String) newIndexDetails.get("name"), is("theFirstField_1_theSecondField_-1"));
}
use of com.mongodb.operation.OrderBy in project mongo-java-driver by mongodb.
the class AddIndexAcceptanceTest method shouldSupportCompoundIndexes.
@Test
public void shouldSupportCompoundIndexes() {
collection.createIndex(new Document("theFirstField", 1).append("theSecondField", 1));
Document newIndexDetails = collection.listIndexes().into(new ArrayList<Document>()).get(1);
Document keys = (Document) newIndexDetails.get("key");
Object theFirstField = keys.get("theFirstField");
assertThat("Index should contain the first key", theFirstField, is(notNullValue()));
OrderBy orderBy = fromInt((Integer) theFirstField);
assertThat("Index created should be ascending", orderBy, is(ASC));
Object theSecondField = keys.get("theSecondField");
assertThat("Index should contain the second key", theSecondField, is(notNullValue()));
orderBy = fromInt((Integer) theSecondField);
assertThat("Index created should be ascending", orderBy, is(ASC));
assertThat("Index name should contain both field names", (String) newIndexDetails.get("name"), is("theFirstField_1_theSecondField_1"));
}
use of com.mongodb.operation.OrderBy in project mongo-java-driver by mongodb.
the class AddIndexAcceptanceTest method shouldSupportCompoundIndexesOfOrderedFieldsAndGeoFields.
@Test
public void shouldSupportCompoundIndexesOfOrderedFieldsAndGeoFields() {
collection.createIndex(new Document("locationField", "2d").append("someOtherField", 1));
Document newIndexDetails = collection.listIndexes().into(new ArrayList<Document>()).get(1);
Document keys = (Document) newIndexDetails.get("key");
Object geoField = keys.get("locationField");
assertThat("Index should contain the first key", geoField, is(notNullValue()));
String geoIndexValue = geoField.toString();
assertThat("Index created should be a geo index", geoIndexValue, is("2d"));
Object orderedField = keys.get("someOtherField");
assertThat("Index should contain the second key", orderedField, is(notNullValue()));
OrderBy orderBy = fromInt((Integer) orderedField);
assertThat("Index created should be ascending", orderBy, is(ASC));
assertThat("Index name should contain both field names", (String) newIndexDetails.get("name"), is("locationField_2d_someOtherField_1"));
}
use of com.mongodb.operation.OrderBy in project mongo-java-driver by mongodb.
the class AddIndexAcceptanceTest method shouldCreateADescendingIndex.
@Test
public void shouldCreateADescendingIndex() {
collection.createIndex(new Document("field", -1));
Document newIndexDetails = collection.listIndexes().into(new ArrayList<Document>()).get(1);
OrderBy order = fromInt((Integer) ((Document) newIndexDetails.get("key")).get("field"));
assertThat("Index created should be descending", order, is(DESC));
}
use of com.mongodb.operation.OrderBy in project mongo-java-driver by mongodb.
the class AddIndexAcceptanceTest method shouldCreateAnAscendingIndex.
@Test
public void shouldCreateAnAscendingIndex() {
collection.createIndex(new Document("field", 1));
Document newIndexDetails = collection.listIndexes().into(new ArrayList<Document>()).get(1);
OrderBy order = fromInt((Integer) ((Document) newIndexDetails.get("key")).get("field"));
assertThat("Index created should be ascending", order, is(ASC));
}