Allow query projection methods .include()
and .exclude()
to accept Collection
#4625
Labels
status: ideal-for-contribution
An issue that a contributor can help us with
type: enhancement
A general enhancement
Milestone
Hi, we have a bunch of APIs that allow our users to specify a comma-separated list of fields that they want to receive back from the API response, which lowers our network bandwidth usage:
Currently, spring-data allows us to project fields on a query using the
include()
andexclude()
methods. However, theinclude()
method only acceptsString
orString...
. Thus, we're forced to add code to convert our Lists into String arrays just to satisfy theinclude()
function's signature.This adds complexity and maintenance overhead even though
Collection
is the more flexible and more common data structure to use in Java code overString[]
.So, I would like to propose adding a new version of
include
andexclude
that acceptsCollection
so that we can directly use modernCollection
implementors (List, Set, etc) for these methods instead of being forced to convert them to primitiveString[]
first?The implementation would be pretty simple, so this should be an easy upgrade that would greatly improve the public API of spring-data-mongo
Query
objects to make them more flexible and usable:(I can raise a PR for this if that's easier for the spring team)
The text was updated successfully, but these errors were encountered: