use of org.springframework.data.mongodb.core.mapping.MongoMappingContext 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\" }"));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class SetOperationUnitTests 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 RelaxedTypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class ProjectionOperationUnitTests method nestedMappedFieldReferenceInArrayField.
// DATAMONGO-2312
@Test
void nestedMappedFieldReferenceInArrayField() {
MongoMappingContext mappingContext = new MongoMappingContext();
Document doc = //
project("author").andArrayOf(Fields.field("title"), "plain - string", ArithmeticOperators.valueOf("title").sum().and(10)).as(//
"myArray").toDocument(new TypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
assertThat(doc).isEqualTo(Document.parse("{ $project: { \"author\" : 1, \"myArray\" : [ \"$ti_t_le\", \"plain - string\", { \"$sum\" : [\"$ti_t_le\", 10] } ] } } ] }"));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class ReactivePerformanceTests method setUp.
@BeforeEach
public void setUp() throws Exception {
mongo = MongoClients.create();
SimpleReactiveMongoDatabaseFactory mongoDbFactory = new SimpleReactiveMongoDatabaseFactory(this.mongo, DATABASE_NAME);
MongoMappingContext context = new MongoMappingContext();
context.setInitialEntitySet(Collections.singleton(Person.class));
context.afterPropertiesSet();
converter = new MappingMongoConverter(new DbRefResolver() {
@Nullable
@Override
public Object resolveReference(MongoPersistentProperty property, Object source, ReferenceLookupDelegate referenceLookupDelegate, MongoEntityReader entityReader) {
return null;
}
@Override
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler proxyHandler) {
return null;
}
@Override
public DBRef createDbRef(org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) {
return null;
}
@Override
public Document fetch(DBRef dbRef) {
return null;
}
@Override
public List<Document> bulkFetch(List<DBRef> dbRefs) {
return null;
}
}, context);
operations = new ReactiveMongoTemplate(mongoDbFactory, converter);
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(operations);
repository = factory.getRepository(ReactivePersonRepository.class);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class PerformanceTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.mongo = MongoClients.create();
SimpleMongoClientDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(this.mongo, DATABASE_NAME);
MongoMappingContext context = new MongoMappingContext();
context.setInitialEntitySet(Collections.singleton(Person.class));
context.afterPropertiesSet();
this.converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), context);
this.operations = new MongoTemplate(new SimpleMongoClientDatabaseFactory(this.mongo, DATABASE_NAME), converter);
MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>(PersonRepository.class);
factory.setMongoOperations(operations);
factory.afterPropertiesSet();
this.repository = factory.getObject();
}
Aggregations