Search in sources :

Example 1 with IndexInfo

use of org.springframework.data.mongodb.core.index.IndexInfo in project spring-data-mongodb by spring-projects.

the class DefaultIndexOperationsIntegrationTests method getIndexInfoShouldBeAbleToRead2dsphereIndex.

// DATAMONGO-1008
@Test
public void getIndexInfoShouldBeAbleToRead2dsphereIndex() {
    collection.createIndex(GEO_SPHERE_2D);
    IndexInfo info = findAndReturnIndexInfo(GEO_SPHERE_2D);
    assertThat(info.getIndexFields().get(0).isGeo()).isEqualTo(true);
}
Also used : IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Example 2 with IndexInfo

use of org.springframework.data.mongodb.core.index.IndexInfo in project spring-data-mongodb by spring-projects.

the class DefaultIndexOperationsIntegrationTests method shouldApplyPartialFilterWithMappedPropertyCorrectly.

// DATAMONGO-1467
@Test
public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
    assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
    IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC).partial(of(where("quantity").gte(10)));
    indexOps.ensureIndex(id);
    IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-mapped-criteria");
    assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"qty\" : { \"$gte\" : 10 } }");
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Example 3 with IndexInfo

use of org.springframework.data.mongodb.core.index.IndexInfo in project spring-data-mongodb by spring-projects.

the class DefaultIndexOperationsIntegrationTests method shouldApplyPartialFilterCorrectly.

// DATAMONGO-1467
@Test
public void shouldApplyPartialFilterCorrectly() {
    assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
    IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC).partial(of(where("q-t-y").gte(10)));
    indexOps.ensureIndex(id);
    IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-criteria");
    assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"q-t-y\" : { \"$gte\" : 10 } }");
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Example 4 with IndexInfo

use of org.springframework.data.mongodb.core.index.IndexInfo in project spring-data-mongodb by spring-projects.

the class DefaultReactiveIndexOperationsTests method shouldApplyPartialFilterCorrectly.

// DATAMONGO-1682
@Test
public void shouldApplyPartialFilterCorrectly() {
    assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
    IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC).partial(of(where("q-t-y").gte(10)));
    StepVerifier.create(indexOps.ensureIndex(id)).expectNextCount(1).verifyComplete();
    // 
    StepVerifier.create(indexOps.getIndexInfo().filter(this.indexByName("partial-with-criteria"))).consumeNextWith(indexInfo -> {
        assertThat(indexInfo.getPartialFilterExpression()).isEqualTo("{ \"q-t-y\" : { \"$gte\" : 10 } }");
    }).verifyComplete();
}
Also used : Document(org.bson.Document) StepVerifier(reactor.test.StepVerifier) AbstractReactiveMongoConfiguration(org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) MongoClients(com.mongodb.reactivestreams.client.MongoClients) Collation(org.springframework.data.mongodb.core.query.Collation) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) MongoClient(com.mongodb.reactivestreams.client.MongoClient) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Assertions(org.assertj.core.api.Assertions) Version(org.springframework.data.util.Version) Assume(org.junit.Assume) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Before(org.junit.Before) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) Test(org.junit.Test) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Configuration(org.springframework.context.annotation.Configuration) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) Test(org.junit.Test)

Example 5 with IndexInfo

use of org.springframework.data.mongodb.core.index.IndexInfo in project spring-data-mongodb by spring-projects.

the class DefaultReactiveIndexOperationsTests method shouldApplyPartialFilterWithMappedPropertyCorrectly.

// DATAMONGO-1682
@Test
public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
    assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
    IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC).partial(of(where("quantity").gte(10)));
    StepVerifier.create(indexOps.ensureIndex(id)).expectNextCount(1).verifyComplete();
    // 
    StepVerifier.create(indexOps.getIndexInfo().filter(this.indexByName("partial-with-mapped-criteria"))).consumeNextWith(indexInfo -> {
        assertThat(indexInfo.getPartialFilterExpression()).isEqualTo("{ \"qty\" : { \"$gte\" : 10 } }");
    }).verifyComplete();
}
Also used : Document(org.bson.Document) StepVerifier(reactor.test.StepVerifier) AbstractReactiveMongoConfiguration(org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) MongoClients(com.mongodb.reactivestreams.client.MongoClients) Collation(org.springframework.data.mongodb.core.query.Collation) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) MongoClient(com.mongodb.reactivestreams.client.MongoClient) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Assertions(org.assertj.core.api.Assertions) Version(org.springframework.data.util.Version) Assume(org.junit.Assume) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Before(org.junit.Before) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) Test(org.junit.Test) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Configuration(org.springframework.context.annotation.Configuration) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)16 Index (org.springframework.data.mongodb.core.index.Index)11 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)10 Document (org.bson.Document)7 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)7 MongoClient (com.mongodb.reactivestreams.client.MongoClient)5 MongoClients (com.mongodb.reactivestreams.client.MongoClients)5 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)5 Predicate (java.util.function.Predicate)5 Assertions (org.assertj.core.api.Assertions)5 Assume (org.junit.Assume)5 Before (org.junit.Before)5 RunWith (org.junit.runner.RunWith)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Configuration (org.springframework.context.annotation.Configuration)5 Direction (org.springframework.data.domain.Sort.Direction)5 AbstractReactiveMongoConfiguration (org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration)5 PartialIndexFilter (org.springframework.data.mongodb.core.index.PartialIndexFilter)5 Field (org.springframework.data.mongodb.core.mapping.Field)5