Search in sources :

Example 21 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class ProjectionOperationUnitTests method typeProjectionShouldMapFieldNames.

// DATAMONGO-2200
@Test
void typeProjectionShouldMapFieldNames() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
    Document document = Aggregation.project(BookRenamed.class).toDocument(new TypeBasedAggregationOperationContext(Book.class, mappingContext, new QueryMapper(converter)));
    Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
    // 
    assertThat(projectClause).hasSize(// 
    2).containsEntry("ti_tl_e", // 
    1).containsEntry("author", 1);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Test(org.junit.jupiter.api.Test)

Example 22 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class GeoNearOperationUnitTests method typedAggregationOperationContext.

private TypeBasedAggregationOperationContext typedAggregationOperationContext(Class<?> type) {
    MongoMappingContext mappingContext = new MongoMappingContext();
    MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
    return new TypeBasedAggregationOperationContext(type, mappingContext, new QueryMapper(converter));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper)

Example 23 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class RedactOperationUnitTests method contextFor.

private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
    if (type == null) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, new MongoMappingContext());
    mongoConverter.afterPropertiesSet();
    return new TypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter)).continueOnMissingFieldReference();
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper)

Example 24 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class UnionWithOperationUnitTests method contextFor.

private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
    if (type == null) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, new MongoMappingContext());
    mongoConverter.afterPropertiesSet();
    return new TypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper)

Example 25 with QueryMapper

use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.

the class AggregationUnitTests method projectOnIdIsAlwaysValid.

// DATAMONGO-2644
@Test
void projectOnIdIsAlwaysValid() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    Document target = new Aggregation(bucket("start"), project("_id")).toDocument("collection-1", new RelaxedTypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
    assertThat(extractPipelineElement(target, 1, "$project")).isEqualTo(Document.parse(" { \"_id\" : \"$_id\" }"));
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) BookWithFieldAnnotation(org.springframework.data.mongodb.core.aggregation.ProjectionOperationUnitTests.BookWithFieldAnnotation) Test(org.junit.jupiter.api.Test)

Aggregations

QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)29 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)19 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)19 Test (org.junit.jupiter.api.Test)14 Document (org.bson.Document)11 BulkOperationContext (org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext)7 UpdateMapper (org.springframework.data.mongodb.core.convert.UpdateMapper)7 BsonDocument (org.bson.BsonDocument)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)3 Index (org.springframework.data.mongodb.core.index.Index)3 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)3 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)3 BeforeConvertEvent (org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent)3 BeforeSaveEvent (org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)3 Test (org.junit.Test)2 MongoConverter (org.springframework.data.mongodb.core.convert.MongoConverter)2 AfterSaveEvent (org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 MongoWriteException (com.mongodb.MongoWriteException)1