DATAMONGO-1183 - Fix field name mapping in IndexOperations.

We now consider the Field annotation when creating indexes via IndexOperations.

Original pull request: #750.
This commit is contained in:
Christoph Strobl
2019-05-15 14:56:11 +02:00
committed by Mark Paluch
parent 684e24aff5
commit e06f326de3
2 changed files with 10 additions and 1 deletions

View File

@@ -127,7 +127,8 @@ public class DefaultIndexOperations implements IndexOperations {
indexOptions = addPartialFilterIfPresent(indexOptions, indexDefinition.getIndexOptions(), entity);
indexOptions = addDefaultCollationIfRequired(indexOptions, entity);
return collection.createIndex(indexDefinition.getIndexKeys(), indexOptions);
Document mappedKeys = mapper.getMappedObject(indexDefinition.getIndexKeys(), entity);
return collection.createIndex(mappedKeys, indexOptions);
});
}

View File

@@ -69,6 +69,14 @@ public class DefaultIndexOperationsUnitTests {
this.template = new MongoTemplate(factory, converter);
}
@Test // DATAMONGO-1183
public void indexOperationsMapFieldNameCorrectly() {
indexOpsFor(Jedi.class).ensureIndex(new Index("name", Direction.DESC));
verify(collection).createIndex(eq(new Document("firstname", -1)), any());
}
@Test // DATAMONGO-1854
public void ensureIndexDoesNotSetCollectionIfNoDefaultDefined() {