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.59k stars 1.07k forks source link

Fixed the bug, a null able list does not work #4734

Open sikandar opened 1 week ago

sikandar commented 1 week ago

If there is a nullable list with values, the implementation should check it instead of wrapping the nullable list (even if it has values) into another newly created list by the Criteria class.

Existing

Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) Output: {"id" : { "$in" : [["667e8b8af76f17213e4d4280"]]}} Wrong

Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids!!) Required !! Output:{"id" :{ "$in" : ["667e8b8af76f17213e4d4280"]}} Correct

After Fix

Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) With and Without !! Output: {"id" : { "$in" : ["667e8b8af76f17213e4d4280"]}} Correct

pivotal-cla commented 1 week ago

@sikandar Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-cla commented 1 week ago

@sikandar Thank you for signing the Contributor License Agreement!

christophstrobl commented 6 days ago

Thank you for getting in touch. Please explain why you think this is necessary and provide throughout testcases for the proposed change since there's a method that accepts a Collection.

As {"$in" : [["n1", "n2"]]} matches differently from {"$in" : ["n1", "n2"]} I think revisiting the arrangement makes sense.