Skip to content

Commit f2c4370

Browse files
Fix meta field mapping when computing fields for projections.
Related to: #3894
1 parent fdff74f commit f2c4370

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/QueryOperations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ Document getMappedFields(@Nullable MongoPersistentEntity<?> entity,
302302
mappedFields = queryMapper.getMappedFields(fields, entity);
303303
} else {
304304
mappedFields = propertyOperations.computeMappedFieldsForProjection(projection, fields);
305+
mappedFields = queryMapper.addMetaAttributes(mappedFields, entity);
305306
}
306307

307308
if (entity.hasTextScoreProperty() && mappedFields.containsKey(entity.getTextScoreProperty().getFieldName())

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ private Document mapFieldsToPropertyNames(Document fields, @Nullable MongoPersis
240240
return target;
241241
}
242242

243+
/**
244+
* Adds missing {@code $meta} representation if required.
245+
*
246+
* @param source must not be {@literal null}.
247+
* @param entity can be {@literal null}.
248+
* @return never {@literal null}.
249+
* @since 3.4
250+
*/
251+
public Document addMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity) {
252+
return mapMetaAttributes(source, entity, MetaMapping.FORCE);
253+
}
254+
243255
private Document mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity,
244256
MetaMapping metaMapping) {
245257

0 commit comments

Comments
 (0)