use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsUnitTests method shouldRetainNestedArrayPathWithPlaceholdersForMappedEntity.
// DATAMONGO-2502
@Test
void shouldRetainNestedArrayPathWithPlaceholdersForMappedEntity() {
DefaultBulkOperations ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(OrderTest.class)), new QueryMapper(converter), new UpdateMapper(converter), null, null));
ops.updateOne(new BasicQuery("{}"), Update.update("items.$.documents.0.fileId", "file-id")).execute();
verify(collection).bulkWrite(captor.capture(), any());
UpdateOneModel<Document> updateModel = (UpdateOneModel<Document>) captor.getValue().get(0);
assertThat(updateModel.getUpdate()).isEqualTo(new Document("$set", new Document("items.$.documents.0.the_file_id", "file-id")));
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsIntegrationTests method createBulkOps.
private BulkOperations createBulkOps(BulkMode mode, Class<?> entityType) {
Optional<? extends MongoPersistentEntity<?>> entity = entityType != null ? Optional.of(operations.getConverter().getMappingContext().getPersistentEntity(entityType)) : Optional.empty();
BulkOperationContext bulkOperationContext = new BulkOperationContext(mode, entity, new QueryMapper(operations.getConverter()), new UpdateMapper(operations.getConverter()), null, null);
DefaultBulkOperations bulkOps = new DefaultBulkOperations(operations, COLLECTION_NAME, bulkOperationContext);
bulkOps.setDefaultWriteConcern(WriteConcern.ACKNOWLEDGED);
return bulkOps;
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldCreateIndexWithCollationCorrectly.
// DATAMONGO-1518
@Test
public void shouldCreateIndexWithCollationCorrectly() {
IndexDefinition id = new Index().named("with-collation").on("xyz", Direction.ASC).collation(Collation.of("de_AT").caseFirst(CaseFirst.off()));
new DefaultIndexOperations(template.getMongoDbFactory(), COLLECTION_NAME, new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
Document expected = //
new Document("locale", "de_AT").append("caseLevel", //
false).append("caseFirst", //
"off").append("strength", //
3).append("numericOrdering", //
false).append("alternate", //
"non-ignorable").append("maxVariable", //
"punct").append("normalization", //
false).append("backwards", false);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "with-collation");
assertThat(info.getCollation()).isPresent();
// version is set by MongoDB server - we remove it to avoid errors when upgrading server version.
Document result = info.getCollation().get();
result.remove("version");
assertThat(result).isEqualTo(expected);
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldFavorExplicitMappingHintViaClass.
// DATAMONGO-1467, DATAMONGO-2198
@Test
public void shouldFavorExplicitMappingHintViaClass() {
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC).partial(of(where("age").gte(10)));
indexOps = new DefaultIndexOperations(template.getMongoDbFactory(), COLLECTION_NAME, new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-inheritance");
assertThat(Document.parse(info.getPartialFilterExpression())).isEqualTo(Document.parse("{ \"a_g_e\" : { \"$gte\" : 10 } }"));
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class UnsetOperationUnitTests 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));
}
Aggregations