diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java index 5566f4a4c8..fbe1c0fb99 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java @@ -16,6 +16,7 @@ package org.springframework.data.mongodb.core.query; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -35,6 +36,7 @@ * @author Christoph Strobl * @author Mark Paluch * @author Owen Q + * @author Kirill Egorov */ public class Field { @@ -124,6 +126,17 @@ public Field projectAs(MongoExpression expression, String field) { */ public Field include(String... fields) { + return include(Arrays.asList(fields)); + } + + /** + * Include one or more {@code fields} to be returned by the query operation. + * + * @param fields the document field names to be included. + * @return {@code this} field projection instance. + */ + public Field include(Collection fields) { + Assert.notNull(fields, "Keys must not be null"); for (String key : fields) { @@ -136,7 +149,7 @@ public Field include(String... fields) { /** * Exclude a single {@code field} from being returned by the query operation. * - * @param field the document field name to be included. + * @param field the document field name to be excluded. * @return {@code this} field projection instance. */ public Field exclude(String field) { @@ -151,12 +164,23 @@ public Field exclude(String field) { /** * Exclude one or more {@code fields} from being returned by the query operation. * - * @param fields the document field names to be included. + * @param fields the document field names to be excluded. * @return {@code this} field projection instance. * @since 3.1 */ public Field exclude(String... fields) { + return exclude(Arrays.asList(fields)); + } + + /** + * Exclude one or more {@code fields} from being returned by the query operation. + * + * @param fields the document field names to be excluded. + * @return {@code this} field projection instance. + */ + public Field exclude(Collection fields) { + Assert.notNull(fields, "Keys must not be null"); for (String key : fields) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java index 451d4a4c05..e6a23199d3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java @@ -60,6 +60,7 @@ * @author Mark Paluch * @author Mehran Behnam * @author Jens Schauder + * @author Kirill Egorov */ public class SimpleMongoRepository implements MongoRepository { @@ -485,7 +486,7 @@ private ExecutableFindOperation.TerminatingFind createQuery(UnaryOperator implements ReactiveMongoRepository { @@ -555,7 +556,7 @@ private ReactiveFindOperation.TerminatingFind createQuery(UnaryOperator