spring-projects / spring-projects/spring-data-mongodb
Fields and projection API are very inconvenient [DATAMONGO-2637]
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Zsombor opened DATAMONGO-2637 and commented
We use a couple of projections in our app to limit the amount of data to transfer, with something like this:
aggregationSteps += Aggregation.project(
"aaaa",
"bbbb",
"cccc",
"dddd"
.... (20 more similar lines)
However, in a refactor, we moved a couple of fields into a sub-entity, and blindly adjusted the projection to this:
aggregationSteps += Aggregation.project(
"aaaa",
"bbbb",
"xxx.cccc",
"dddd"
... (20 more similar lines)
Which surprisingly doesn't work as expected.
The smallest solution, which I could find is:
val fields = listOf(
"aaaa",
"bbbb",
"xxx.cccc",
"dddd"
... (20 more similar lines)
).map { Fields.field(it, it) }
aggregationSteps += Aggregation.project(Fields.from(*fields.toTypedArray()))
So the issue is:
- Aggregation.project(
String... names)and Fields.fields(
String... names) has a surprising default behavior - There is no API which takes an array of strings, or a list of strings as field names for projections
- There is no API which takes a list of Fields for projections
Affects: 3.0.4 (Neumann SR4)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the Aggregation.project(String... names) and Fields.fields(String... names) APIs and their projection-related types. Check how nested names such as "xxx.cccc" are interpreted, then determine the API changes needed for string collections and lists of Fields. Done means projections support the requested field forms without the current surprising behavior, with regression coverage for nested fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100