Skip to content

AddFieldsOperationBuilder.addFieldWithValueOf should treat String value as Field reference #4933

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
crmky opened this issue Apr 2, 2025 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@crmky
Copy link

crmky commented Apr 2, 2025

The current implementation treat String value as Fields instead of Field. However org.springframework.data.mongodb.core.aggregation.DocumentEnhancingOperation.computeValue(Object, AggregationOperationContext) doesn't support Fields but only Field, the generated BSON document is incorrect.

I think change this line from:

valueMap.put(field, value instanceof String stringValue ? Fields.fields(stringValue) : value);

to

valueMap.put(field, value instanceof String stringValue ? Fields.field(stringValue) : value);

should fix that issue.

@christophstrobl
Copy link
Member

Good catch @crmky - thanks for reporting.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 14, 2025
kssumin added a commit to kssumin/spring-data-mongodb that referenced this issue May 2, 2025
This commit modifies the AddFieldsOperationBuilder to correctly treat String values as field references.
When a String value is passed, it is now interpreted as a reference to another field, following MongoDB's field reference syntax.

Closes spring-projects#4933

Signed-off-by: kssumin <201566@jnu.ac.kr>
christophstrobl pushed a commit that referenced this issue May 5, 2025
This commit modifies the AddFieldsOperationBuilder to correctly treat String values as field references.
When a String value is passed, it is now interpreted as a reference to another field, following MongoDB's field reference syntax.

Resolves: #4933
Original Pull Request: #4959

Signed-off-by: kssumin <201566@jnu.ac.kr>
christophstrobl added a commit that referenced this issue May 5, 2025
Use single field reference instead of invalid multi field.

See: #4933
christophstrobl added a commit that referenced this issue May 5, 2025
Use single field reference instead of invalid multi field.

See: #4933
christophstrobl pushed a commit that referenced this issue May 5, 2025
This commit modifies the AddFieldsOperationBuilder to correctly treat String values as field references.
When a String value is passed, it is now interpreted as a reference to another field, following MongoDB's field reference syntax.

Resolves: #4933
Original Pull Request: #4959

Signed-off-by: kssumin <201566@jnu.ac.kr>
christophstrobl added a commit that referenced this issue May 5, 2025
Use single field reference instead of invalid multi field.

See: #4933
@christophstrobl christophstrobl added this to the 4.3.12 (2024.0.12) milestone May 5, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants