use of com.mongodb.client.model.CountOptions in project mongo-java-driver by mongodb.
the class UpdateAcceptanceTest method shouldUpdateASingleDocumentMatchingTheSelectorWhenUsingUpdateOne.
@Test
public void shouldUpdateASingleDocumentMatchingTheSelectorWhenUsingUpdateOne() {
// 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.updateOne(filter, incrementXValueByOne);
// Then
assertThat(collection.count(new Document("x", 4), new CountOptions()), is(1L));
}
use of com.mongodb.client.model.CountOptions in project mongo-java-driver by mongodb.
the class JsonPoweredCrudTestHelper method getCountDocumentsResult.
BsonDocument getCountDocumentsResult(final BsonDocument collectionOptions, final BsonDocument arguments, @Nullable final ClientSession clientSession) {
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")));
}
BsonDocument filter = arguments.getDocument("filter", new BsonDocument());
int count;
if (clientSession == null) {
count = (int) getCollection(collectionOptions).countDocuments(filter, options);
} else {
count = (int) getCollection(collectionOptions).countDocuments(clientSession, filter, options);
}
return toResult(count);
}
use of com.mongodb.client.model.CountOptions in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method existsShouldUseDefaultCollationWhenPresent.
// DATAMONGO-1854
@Test
void existsShouldUseDefaultCollationWhenPresent() {
template.exists(new BasicQuery("{}"), Sith.class);
ArgumentCaptor<CountOptions> options = ArgumentCaptor.forClass(CountOptions.class);
verify(collection).countDocuments(any(), options.capture());
assertThat(options.getValue().getCollation()).isEqualTo(com.mongodb.client.model.Collation.builder().locale("de_AT").build());
}
use of com.mongodb.client.model.CountOptions in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUnitTests method countShouldApplyQueryHintIfPresent.
// DATAMONGO-2360
@Test
void countShouldApplyQueryHintIfPresent() {
Document queryHint = new Document("age", 1);
template.count(new Query().withHint(queryHint), Person.class, "star-wars").subscribe();
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 countShouldApplyQueryHintAsIndexNameIfPresent.
// DATAMONGO-2365
@Test
void countShouldApplyQueryHintAsIndexNameIfPresent() {
template.count(new Query().withHint("idx-1"), Person.class, "star-wars").subscribe();
ArgumentCaptor<CountOptions> options = ArgumentCaptor.forClass(CountOptions.class);
verify(collection).countDocuments(any(), options.capture());
assertThat(options.getValue().getHintString()).isEqualTo("idx-1");
}
Aggregations