spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Custom Mongo queries inexplicably return zero results after upgrading to 3.0.8.RELEASE or later (spring-boot dep mgmt: 2.3.10.RELEASE or later) #3658

Open oliverlockwood opened 3 years ago

oliverlockwood commented 3 years ago

I've created a repo to demonstrate the issue, at https://github.com/oliverlockwood/mongodb-issue-demonstration, based on following the guidelines at https://spring.io/guides/gs/accessing-data-mongodb/.

That repo has a clear README but I'll highlight the main points here as well.

I therefore conclude this is a regression in spring-data-mongodb, but I can't for the life of me figure out why it stops returning results.

I hope this in combination with the repo is enough context for you to investigate; please advise if you need me to provide any more information.

Many thanks!

christophstrobl commented 3 years ago

thanks for reporting and the sample - we'll have a look.

mp911de commented 3 years ago

Looks like it is related to #3659.

oliverlockwood commented 3 years ago

@mp911de that's interesting, and slightly surprises me, given the different affected versions (the ticket you refer is noted as a regression in versions after 3.1.9, while this ticket is a regression in versions after 3.0.7).

Still, I look forward to hearing more and will track both issues.

mp911de commented 3 years ago

We had a change where we updated mapping of property paths pointing into collection and map-like structures that maps errornously additionalData.name into additionalData.name.name.

There's quite a bit of a mismatch in the data model. additionalData is defined as Map<String, DataValue> while it actually is List<DataValue>. Changing the data type to additionalData fixes the problem.

We map queries against the domain model so trying to compare additionalData.name=foo againstMap<String, DataValue>describes an attempt to query whether the map (subdocument)additionalDatacontains a fieldnamewith the valuefoo while DataValue isn't compatible with that representation.

In any case, trying to query into a map should render the proper field name into the query.

oliverlockwood commented 3 years ago

Thanks for your comment on 18th June, @mp911de. Any news on when this might be fixed? I'm a bit worried about getting stuck on an old version of spring-data-mongodb while we continue to keep updating our platform (next step is to move to Spring Boot 2.5.x).,

mp911de commented 3 years ago

You can fix the issue immediately within your code by aligning the data model to the actual representation in your MongoDB documents. Other than that, we need to revisit the entire map and array position translation that isn't planned short term.