Search in sources :

Example 6 with CountOptions

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);
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) CountOptions(com.mongodb.client.model.CountOptions) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 7 with CountOptions

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);
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) CountOptions(com.mongodb.client.model.CountOptions) Test(org.junit.jupiter.api.Test)

Example 8 with CountOptions

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);
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) CountOptions(com.mongodb.client.model.CountOptions) Test(org.junit.jupiter.api.Test)

Example 9 with CountOptions

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());
        }
    };
}
Also used : CountOptions(com.mongodb.client.model.CountOptions)

Example 10 with CountOptions

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));
}
Also used : CountOptions(com.mongodb.client.model.CountOptions) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

CountOptions (com.mongodb.client.model.CountOptions)17 Document (org.bson.Document)8 Test (org.junit.jupiter.api.Test)7 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)6 Test (org.junit.Test)5 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)4 Query (org.springframework.data.mongodb.core.query.Query)4 BsonDocument (org.bson.BsonDocument)3 Bson (org.bson.conversions.Bson)3 UpdateOptions (com.mongodb.client.model.UpdateOptions)2 EstimatedDocumentCountOptions (com.mongodb.client.model.EstimatedDocumentCountOptions)1 ClientSession (com.mongodb.reactivestreams.client.ClientSession)1 StopWatch (core.framework.util.StopWatch)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 MongoDBResult (org.apache.gora.mongodb.query.MongoDBResult)1 GoraException (org.apache.gora.util.GoraException)1 ArrayMemory (php.runtime.memory.ArrayMemory)1