Fix meta field mapping when computing fields for projections.

Related to: #3894
This commit is contained in:
Christoph Strobl
2021-12-14 14:58:53 +01:00
parent fdff74f7b5
commit f2c4370584
2 changed files with 13 additions and 0 deletions

View File

@@ -302,6 +302,7 @@ class QueryOperations {
mappedFields = queryMapper.getMappedFields(fields, entity);
} else {
mappedFields = propertyOperations.computeMappedFieldsForProjection(projection, fields);
mappedFields = queryMapper.addMetaAttributes(mappedFields, entity);
}
if (entity.hasTextScoreProperty() && mappedFields.containsKey(entity.getTextScoreProperty().getFieldName())

View File

@@ -240,6 +240,18 @@ public class QueryMapper {
return target;
}
/**
* Adds missing {@code $meta} representation if required.
*
* @param source must not be {@literal null}.
* @param entity can be {@literal null}.
* @return never {@literal null}.
* @since 3.4
*/
public Document addMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity) {
return mapMetaAttributes(source, entity, MetaMapping.FORCE);
}
private Document mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity,
MetaMapping metaMapping) {