use of com.mongodb.client.model.CountOptions in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method countShouldApplyQueryHintIfPresent.
// DATAMONGO-2360
@Test
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).countDocuments(any(), options.capture());
assertThat(options.getValue().getHint()).isEqualTo(queryHint);
}
use of com.mongodb.client.model.CountOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method countShouldUseSkipFromQuery.
// DATAMONGO-1783
@Test
void countShouldUseSkipFromQuery() {
template.count(new Query().skip(10), Person.class, "star-wars").subscribe();
ArgumentCaptor<CountOptions> options = ArgumentCaptor.forClass(CountOptions.class);
verify(collection).countDocuments(any(), options.capture());
assertThat(options.getValue().getSkip()).isEqualTo(10);
}
use of com.mongodb.client.model.CountOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method countShouldUseLimitFromQuery.
// DATAMONGO-1783
@Test
void countShouldUseLimitFromQuery() {
template.count(new Query().limit(100), Person.class, "star-wars").subscribe();
ArgumentCaptor<CountOptions> options = ArgumentCaptor.forClass(CountOptions.class);
verify(collection).countDocuments(any(), options.capture());
assertThat(options.getValue().getLimit()).isEqualTo(100);
}
use of com.mongodb.client.model.CountOptions in project mongo-java-driver by mongodb.
the class CrudTest method getCountMongoOperation.
private MongoOperationLong getCountMongoOperation(final BsonDocument arguments) {
return new MongoOperationLong() {
@Override
public void execute() {
CountOptions options = new CountOptions();
if (arguments.containsKey("skip")) {
options.skip(arguments.getNumber("skip").intValue());
}
if (arguments.containsKey("limit")) {
options.limit(arguments.getNumber("limit").intValue());
}
if (arguments.containsKey("collation")) {
options.collation(getCollation(arguments.getDocument("collation")));
}
collection.count(arguments.getDocument("filter"), options, getCallback());
}
};
}
use of com.mongodb.client.model.CountOptions in project mongo-java-driver by mongodb.
the class UpdateAcceptanceTest method shouldUpdateAllDocumentsMatchingTheSelectorWhenUsingUpdate.
@Test
public void shouldUpdateAllDocumentsMatchingTheSelectorWhenUsingUpdate() {
// Given
Document firstDocument = new Document("a", 1).append("x", 3);
collection.insertOne(firstDocument);
Document secondDocument = new Document("a", 1).append("x", 3);
collection.insertOne(secondDocument);
// When
Document filter = new Document("a", 1);
Document incrementXValueByOne = new Document("$inc", new Document("x", 1));
collection.updateMany(filter, incrementXValueByOne);
// Then
assertThat(collection.count(new Document("x", 4), new CountOptions()), is(2L));
}
Aggregations