Search in sources :

Example 1 with DirectFieldReference

use of org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference in project spring-data-mongodb by spring-projects.

the class TypeBasedAggregationOperationContext method getReferenceFor.

private FieldReference getReferenceFor(Field field) {
    PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(field.getTarget(), type);
    Field mappedField = field(field.getName(), propertyPath.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE));
    return new DirectFieldReference(new ExposedField(mappedField, true));
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) DirectFieldReference(org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference)

Example 2 with DirectFieldReference

use of org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference in project spring-data-mongodb by spring-projects.

the class TypeBasedAggregationOperationContextUnitTests method aliasesIdFieldCorrectly.

// DATAMONGO-806
@Test
public void aliasesIdFieldCorrectly() {
    AggregationOperationContext context = getContext(Foo.class);
    assertThat(context.getReference("id"), is(new DirectFieldReference(new ExposedField(field("id", "_id"), true))));
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) DirectFieldReference(org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference) Test(org.junit.Test)

Aggregations

DirectFieldReference (org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference)2 ExposedField (org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField)2 Test (org.junit.Test)1 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)1