DATAMONGO-2360 - Apply query hint to count queries.
Original pull request: #788.
This commit is contained in:
committed by
Mark Paluch
parent
801a3645a9
commit
9093f8d8af
@@ -1172,6 +1172,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
if (query.getSkip() > 0) {
|
||||
options.skip((int) query.getSkip());
|
||||
}
|
||||
if (StringUtils.hasText(query.getHint())) {
|
||||
options.hint(Document.parse(query.getHint()));
|
||||
}
|
||||
|
||||
Document document = queryMapper.getMappedObject(query.getQueryObject(),
|
||||
Optional.ofNullable(entityClass).map(it -> mappingContext.getPersistentEntity(entityClass)));
|
||||
|
||||
@@ -932,6 +932,18 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
.isEqualTo(com.mongodb.client.model.Collation.builder().locale("fr").build());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2360
|
||||
public void countShouldApplyQueryHintIfPresent() {
|
||||
|
||||
Document queryHint = new Document("age", 1);
|
||||
template.count(new BasicQuery("{}").withHint(queryHint), AutogenerateableId.class);
|
||||
|
||||
ArgumentCaptor<CountOptions> options = ArgumentCaptor.forClass(CountOptions.class);
|
||||
verify(collection).count(any(), options.capture());
|
||||
|
||||
assertThat(options.getValue().getHint()).isEqualTo(queryHint);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1733
|
||||
public void appliesFieldsWhenInterfaceProjectionIsClosedAndQueryDoesNotDefineFields() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user