Compare commits
21 Commits
2.2.4.RELE
...
2.2.5.RELE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdd7a2008b | ||
|
|
c2b80fddd8 | ||
|
|
8eaa8119e6 | ||
|
|
5fccadd41e | ||
|
|
5d0ab340e3 | ||
|
|
5d7e9199de | ||
|
|
5e2c65a650 | ||
|
|
1f5553d2d8 | ||
|
|
40d5ab050f | ||
|
|
1629ba11b2 | ||
|
|
6e94f138d5 | ||
|
|
1b7273db42 | ||
|
|
8857903831 | ||
|
|
69cacb5fe3 | ||
|
|
ba4b958114 | ||
|
|
6d971ef2c8 | ||
|
|
03ff37db92 | ||
|
|
428126ef75 | ||
|
|
aee242c52a | ||
|
|
1299f78e80 | ||
|
|
fc3d13d5bc |
6
pom.xml
6
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.2.4.RELEASE</version>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Spring Data MongoDB</name>
|
||||
@@ -15,7 +15,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data.build</groupId>
|
||||
<artifactId>spring-data-parent</artifactId>
|
||||
<version>2.2.4.RELEASE</version>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -26,7 +26,7 @@
|
||||
<properties>
|
||||
<project.type>multi</project.type>
|
||||
<dist.id>spring-data-mongodb</dist.id>
|
||||
<springdata.commons>2.2.4.RELEASE</springdata.commons>
|
||||
<springdata.commons>2.2.5.RELEASE</springdata.commons>
|
||||
<mongo>3.11.2</mongo>
|
||||
<mongo.reactivestreams>1.12.0</mongo.reactivestreams>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.2.4.RELEASE</version>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.2.4.RELEASE</version>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||
<version>2.2.4.RELEASE</version>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ import com.mongodb.DBRef;
|
||||
* @author Jordi Llach
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware, ValueResolver {
|
||||
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware {
|
||||
|
||||
private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions. Parent object was: %4$s";
|
||||
private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!";
|
||||
@@ -131,7 +131,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
this.idMapper = new QueryMapper(this);
|
||||
|
||||
this.spELContext = new SpELContext(DocumentPropertyAccessor.INSTANCE);
|
||||
this.dbRefProxyHandler = new DefaultDbRefProxyHandler(spELContext, mappingContext, MappingMongoConverter.this);
|
||||
this.dbRefProxyHandler = new DefaultDbRefProxyHandler(spELContext, mappingContext,
|
||||
MappingMongoConverter.this::getValueInternal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +432,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
SpELExpressionEvaluator evaluator) {
|
||||
|
||||
return new DefaultDbRefResolverCallback(documentAccessor.getDocument(), currentPath, evaluator,
|
||||
MappingMongoConverter.this);
|
||||
MappingMongoConverter.this::getValueInternal);
|
||||
}
|
||||
|
||||
private void readAssociation(Association<MongoPersistentProperty> association, PersistentPropertyAccessor<?> accessor,
|
||||
@@ -1047,7 +1048,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.convert.ValueResolver#getValueInternal(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty, com.mongodb.Document, org.springframework.data.mapping.model.SpELExpressionEvaluator, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator,
|
||||
ObjectPath path) {
|
||||
return new MongoDbPropertyValueProvider(bson, evaluator, path).getPropertyValue(prop);
|
||||
@@ -1491,7 +1492,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
DbRefResolverCallback callback = new DefaultDbRefResolverCallback(accessor.getDocument(), path, evaluator,
|
||||
MappingMongoConverter.this);
|
||||
MappingMongoConverter.this::getValueInternal);
|
||||
|
||||
DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null;
|
||||
return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler);
|
||||
|
||||
@@ -19,12 +19,14 @@ import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Internal API to trigger the resolution of properties.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
interface ValueResolver {
|
||||
|
||||
@@ -38,6 +40,6 @@ interface ValueResolver {
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator,
|
||||
ObjectPath path);
|
||||
@Nullable
|
||||
Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator, ObjectPath path);
|
||||
}
|
||||
|
||||
@@ -79,8 +79,14 @@ public class BasicMongoPersistentProperty extends AnnotationBasedPersistentPrope
|
||||
this.fieldNamingStrategy = fieldNamingStrategy == null ? PropertyNameFieldNamingStrategy.INSTANCE
|
||||
: fieldNamingStrategy;
|
||||
|
||||
if (isIdProperty() && getFieldName() != ID_FIELD_NAME) {
|
||||
LOG.warn("Customizing field name for id property not allowed! Custom name will not be considered!");
|
||||
if (isIdProperty() && hasExplicitFieldName()) {
|
||||
|
||||
String annotatedName = getAnnotatedFieldName();
|
||||
if (!ID_FIELD_NAME.equals(annotatedName)) {
|
||||
LOG.warn(
|
||||
"Customizing field name for id property '{}.{}' is not allowed! Custom name ('{}') will not be considered!",
|
||||
owner.getName(), getName(), annotatedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +173,11 @@ public class BasicMongoPersistentProperty extends AnnotationBasedPersistentPrope
|
||||
|
||||
FieldType fieldType = fieldAnnotation.targetType();
|
||||
if (fieldType == FieldType.IMPLICIT) {
|
||||
|
||||
if (isEntity()) {
|
||||
return org.bson.Document.class;
|
||||
}
|
||||
|
||||
return getType();
|
||||
}
|
||||
|
||||
|
||||
@@ -547,13 +547,11 @@ public class Query {
|
||||
}
|
||||
};
|
||||
|
||||
target.criteria.putAll(source.criteria);
|
||||
target.skip = source.skip;
|
||||
target.limit = source.limit;
|
||||
target.sort = Sort.unsorted().and(source.sort);
|
||||
target.hint = source.hint;
|
||||
target.collation = source.collation;
|
||||
target.restrictedTypes.addAll(source.restrictedTypes);
|
||||
target.skip = source.getSkip();
|
||||
target.limit = source.getLimit();
|
||||
target.hint = source.getHint();
|
||||
target.collation = source.getCollation();
|
||||
target.restrictedTypes.addAll(source.getRestrictedTypes());
|
||||
|
||||
if (source.getMeta().hasValues()) {
|
||||
target.setMeta(new Meta(source.getMeta()));
|
||||
|
||||
@@ -18,6 +18,9 @@ package org.springframework.data.mongodb.repository.query;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
@@ -168,6 +171,17 @@ interface ReactiveMongoQueryExecution {
|
||||
|
||||
ReturnedType returnedType = processor.getReturnedType();
|
||||
|
||||
if (isVoid(returnedType)) {
|
||||
|
||||
if (source instanceof Mono) {
|
||||
return ((Mono<?>) source).then();
|
||||
}
|
||||
|
||||
if (source instanceof Publisher) {
|
||||
return Flux.from((Publisher<?>) source).then();
|
||||
}
|
||||
}
|
||||
|
||||
if (ClassUtils.isPrimitiveOrWrapper(returnedType.getReturnedType())) {
|
||||
return source;
|
||||
}
|
||||
@@ -182,4 +196,8 @@ interface ReactiveMongoQueryExecution {
|
||||
return processor.processResult(source, converter);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isVoid(ReturnedType returnedType) {
|
||||
return returnedType.getReturnedType().equals(Void.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ class JsonScanner {
|
||||
boolean isExpression = false;
|
||||
int parenthesisCount = 0;
|
||||
|
||||
while (c == '$' || c == '_' || Character.isLetterOrDigit(c) || c == '#' || c == '{' || c == '[' || c == ']'
|
||||
while (c == '$' || c == '_' || Character.isLetterOrDigit(c) || c == '#' || c == '{' || c == '['
|
||||
|| (isExpression && isExpressionAllowedChar(c))) {
|
||||
|
||||
if (charCount == 0 && c == '#') {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -54,7 +55,7 @@ public class BasicMongoPersistentPropertyUnitTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
entity = new BasicMongoPersistentEntity<Person>(ClassTypeInformation.from(Person.class));
|
||||
entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(Person.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,12 +224,19 @@ public class BasicMongoPersistentPropertyUnitTests {
|
||||
assertThat(property.getFieldType()).isEqualTo(ObjectId.class);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2460
|
||||
public void fieldTypeShouldBeDocumentForPropertiesAnnotatedIdWhenAComplexTypeAndFieldTypeImplicit() {
|
||||
|
||||
MongoPersistentProperty property = getPropertyFor(WithComplexId.class, "id");
|
||||
assertThat(property.getFieldType()).isEqualTo(Document.class);
|
||||
}
|
||||
|
||||
private MongoPersistentProperty getPropertyFor(Field field) {
|
||||
return getPropertyFor(entity, field);
|
||||
}
|
||||
|
||||
private static <T> MongoPersistentProperty getPropertyFor(Class<T> type, String fieldname) {
|
||||
return getPropertyFor(new BasicMongoPersistentEntity<T>(ClassTypeInformation.from(type)), fieldname);
|
||||
return getPropertyFor(new BasicMongoPersistentEntity<>(ClassTypeInformation.from(type)), fieldname);
|
||||
}
|
||||
|
||||
private static MongoPersistentProperty getPropertyFor(MongoPersistentEntity<?> entity, String fieldname) {
|
||||
@@ -329,4 +337,14 @@ public class BasicMongoPersistentPropertyUnitTests {
|
||||
|
||||
@MongoId(FieldType.OBJECT_ID) String id;
|
||||
}
|
||||
|
||||
static class ComplexId {
|
||||
|
||||
String value;
|
||||
}
|
||||
|
||||
static class WithComplexId {
|
||||
|
||||
@Id @org.springframework.data.mongodb.core.mapping.Field ComplexId id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
@@ -337,6 +337,19 @@ public class QueryTests {
|
||||
.isNotEqualTo(source.getQueryObject());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2478
|
||||
public void queryOfShouldWorkOnProxiedObjects() {
|
||||
|
||||
BasicQuery source = new BasicQuery("{ 'foo' : 'bar'}", "{ '_id' : -1, 'foo' : 1 }");
|
||||
source.withHint("the hint");
|
||||
source.limit(10);
|
||||
source.setSortObject(new Document("_id", 1));
|
||||
|
||||
Query target = Query.of((Query) new ProxyFactory(source).getProxy());
|
||||
|
||||
compareQueries(target, source);
|
||||
}
|
||||
|
||||
private void compareQueries(Query actual, Query expected) {
|
||||
|
||||
assertThat(actual.getCollation()).isEqualTo(expected.getCollation());
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.mongodb.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -575,6 +577,18 @@ public class ReactiveMongoRepositoryTests {
|
||||
.expectNext("lastname").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2406
|
||||
public void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
|
||||
repository.deleteByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
template.find(query(where("lastname").is(dave.getLastname())), Person.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
interface ReactivePersonRepository
|
||||
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> {
|
||||
|
||||
@@ -645,6 +659,8 @@ public class ReactiveMongoRepositoryTests {
|
||||
|
||||
@Query(value = "{_id:?0}")
|
||||
Mono<org.bson.Document> findDocumentById(String id);
|
||||
|
||||
Mono<Void> deleteByLastname(String lastname);
|
||||
}
|
||||
|
||||
interface ReactiveContactRepository extends ReactiveMongoRepository<Contact, String> {}
|
||||
|
||||
@@ -220,6 +220,41 @@ public class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(target).isEqualTo(new Document("name", "value"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindUnquotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [?0] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindMultipleUnquotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [?0,?1] } }", "dalinar", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in",Arrays.asList("dalinar", "kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindUnquotedParameterInArrayWithSpaces() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : [ ?0 ] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindQuotedParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : ['?0'] } }", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("kohlin"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2476
|
||||
public void bindQuotedMulitParameterInArray() {
|
||||
|
||||
Document target = parse("{ 'name' : { $in : ['?0,?1'] } }", "dalinar", "kohlin");
|
||||
assertThat(target).isEqualTo(new Document("name", new Document("$in", Collections.singletonList("dalinar,kohlin"))));
|
||||
}
|
||||
|
||||
private static Document parse(String json, Object... args) {
|
||||
|
||||
ParameterBindingJsonReader reader = new ParameterBindingJsonReader(json, args);
|
||||
|
||||
@@ -28,7 +28,10 @@ public class Person {
|
||||
----
|
||||
====
|
||||
|
||||
Note that the domain type shown in the preceding example has a property named `id` of type `ObjectId`. The default serialization mechanism used in `MongoTemplate` (which backs the repository support) regards properties named `id` as the document ID. Currently, we support `String`, `ObjectId`, and `BigInteger` as ID types. Now that we have a domain object, we can define an interface that uses it, as follows:
|
||||
Note that the domain type shown in the preceding example has a property named `id` of type `String`. The default serialization mechanism used in `MongoTemplate` (which backs the repository support) regards properties named `id` as the document ID. Currently, we support `String`, `ObjectId`, and `BigInteger` as ID types.
|
||||
Please see <<mongo-template.id-handling, ID mapping>> for more information about on how the `id` field is handled in the mapping layer.
|
||||
|
||||
Now that we have a domain object, we can define an interface that uses it, as follows:
|
||||
|
||||
.Basic repository interface to persist Person entities
|
||||
====
|
||||
@@ -93,7 +96,7 @@ class ApplicationConfig extends AbstractMongoConfiguration {
|
||||
|
||||
@Override
|
||||
protected String getMappingBasePackage() {
|
||||
return "com.oreilly.springdata.mongodb"
|
||||
return "com.oreilly.springdata.mongodb";
|
||||
}
|
||||
}
|
||||
----
|
||||
@@ -311,7 +314,7 @@ The following example shows how to define a `near` query that finds all persons
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
// { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance}}
|
||||
List<Person> findByLocationNear(Point location, Distance distance);
|
||||
@@ -344,7 +347,7 @@ Spring Data MongoDb supports geo-near queries, as the following example shows:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
// {'geoNear' : 'location', 'near' : [x, y] }
|
||||
GeoResults<Person> findByLocationNear(Point location);
|
||||
@@ -371,7 +374,7 @@ By adding the `org.springframework.data.mongodb.repository.Query` annotation to
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
@Query("{ 'firstname' : ?0 }")
|
||||
List<Person> findByThePersonsFirstname(String firstname);
|
||||
@@ -387,7 +390,7 @@ You can also use the filter property to restrict the set of properties that is m
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
@Query(value="{ 'firstname' : ?0 }", fields="{ 'firstname' : 1, 'lastname' : 1}")
|
||||
List<Person> findByThePersonsFirstname(String firstname);
|
||||
@@ -438,7 +441,7 @@ to declare the predicate value for `lastname` (which is equivalent to the `?0` p
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
@Query("{'lastname': ?#{[0]} }")
|
||||
List<Person> findByQueryWithExpression(String param0);
|
||||
@@ -450,7 +453,7 @@ used in conjunction with JSON reveal a side-effect, because Map-like declaration
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends MongoRepository<Person, String>
|
||||
public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
|
||||
@Query("{'id': ?#{ [0] ? {$exists :true} : [1] }}")
|
||||
List<Person> findByQueryWithExpressionAndNestedObject(boolean param0, String param1);
|
||||
|
||||
@@ -41,7 +41,10 @@ public class Person {
|
||||
----
|
||||
====
|
||||
|
||||
Note that the entity defined in the preceding example has a property named `id` of type `ObjectId`. The default serialization mechanism used in `MongoTemplate` (which backs the repository support) regards properties named `id` as the document ID. Currently, we support `String`, `ObjectId`, and `BigInteger` as id-types. The following example shows how to create an interface that defines queries against the `Person` object from the preceding example:
|
||||
Note that the entity defined in the preceding example has a property named `id` of type `String`. The default serialization mechanism used in `MongoTemplate` (which backs the repository support) regards properties named `id` as the document ID. Currently, we support `String`, `ObjectId`, and `BigInteger` as id-types.
|
||||
Please see <<mongo-template.id-handling, ID mapping>> for more information about on how the `id` field is handled in the mapping layer.
|
||||
|
||||
The following example shows how to create an interface that defines queries against the `Person` object from the preceding example:
|
||||
|
||||
.Basic repository interface to persist Person entities
|
||||
====
|
||||
@@ -93,7 +96,7 @@ class ApplicationConfig extends AbstractReactiveMongoConfiguration {
|
||||
|
||||
@Override
|
||||
protected String getMappingBasePackage() {
|
||||
return "com.oreilly.springdata.mongodb"
|
||||
return "com.oreilly.springdata.mongodb";
|
||||
}
|
||||
}
|
||||
----
|
||||
@@ -117,6 +120,20 @@ public class PersonRepositoryTests {
|
||||
----
|
||||
====
|
||||
|
||||
WARNING: The `Page` return type (as in `Mono<Page>`) is not supported by reactive repositories.
|
||||
|
||||
It is possible to use `Pageable` in derived finder methods, to pass on `sort`, `limit` and `offset` parameters to the query to reduce load and network traffic.
|
||||
The returned `Flux` will only emit data within the declared range.
|
||||
|
||||
.Limit and Offset with reactive repositories
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
Pageable page = PageRequest.of(1, 10, Sort.by("lastname"));
|
||||
Flux<Person> persons = repository.findByFirstnameOrderByLastname("luke", page);
|
||||
----
|
||||
====
|
||||
|
||||
[[mongo.reactive.repositories.features]]
|
||||
== Features
|
||||
|
||||
@@ -143,7 +160,7 @@ The following example shows how to define a `near` query that finds all persons
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends ReactiveMongoRepository<Person, String>
|
||||
public interface PersonRepository extends ReactiveMongoRepository<Person, String> {
|
||||
|
||||
// { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance}}
|
||||
Flux<Person> findByLocationNear(Point location, Distance distance);
|
||||
@@ -178,7 +195,7 @@ Spring Data MongoDB supports geo-near queries, as the following example shows:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface PersonRepository extends ReactiveMongoRepository<Person, String>
|
||||
public interface PersonRepository extends ReactiveMongoRepository<Person, String> {
|
||||
|
||||
// {'geoNear' : 'location', 'near' : [x, y] }
|
||||
Flux<GeoResult<Person>> findByLocationNear(Point location);
|
||||
|
||||
@@ -1,6 +1,85 @@
|
||||
Spring Data MongoDB Changelog
|
||||
=============================
|
||||
|
||||
Changes in version 2.2.5.RELEASE (2020-02-26)
|
||||
---------------------------------------------
|
||||
* DATAMONGO-2478 - NPE when using Query annotation and with sort and pageable.
|
||||
* DATAMONGO-2476 - JsonParseException: JSON reader was expecting a value but found '}'.
|
||||
* DATAMONGO-2464 - Fix code examples in reference documentation.
|
||||
* DATAMONGO-2460 - @Field annotation behaviour changed.
|
||||
* DATAMONGO-2459 - Update Documentation of Reactive Repositories to mention usage of PageRequest.
|
||||
* DATAMONGO-2457 - Reference documentation: Text does not match with code example.
|
||||
* DATAMONGO-2453 - Release 2.2.5 (Moore SR5).
|
||||
* DATAMONGO-2406 - Allow Mono<Void> as return type for derived deleteBy queries.
|
||||
* DATAMONGO-2079 - MappingMongoConverter cannot be proxied because it implements the package-private ValueResolver interface.
|
||||
|
||||
|
||||
Changes in version 2.1.16.RELEASE (2020-02-26)
|
||||
----------------------------------------------
|
||||
* DATAMONGO-2464 - Fix code examples in reference documentation.
|
||||
* DATAMONGO-2459 - Update Documentation of Reactive Repositories to mention usage of PageRequest.
|
||||
* DATAMONGO-2457 - Reference documentation: Text does not match with code example.
|
||||
* DATAMONGO-2452 - Release 2.1.16 (Lovelace SR16).
|
||||
* DATAMONGO-2079 - MappingMongoConverter cannot be proxied because it implements the package-private ValueResolver interface.
|
||||
|
||||
|
||||
Changes in version 3.0.0.M3 (2020-02-12)
|
||||
----------------------------------------
|
||||
* DATAMONGO-2470 - Adapt tests to AssertJ 3.15.0.
|
||||
* DATAMONGO-2464 - Fix code examples in reference documentation.
|
||||
* DATAMONGO-2462 - Move off deprecated EntityInstantiators.
|
||||
* DATAMONGO-2461 - Fix Jenkins build.
|
||||
* DATAMONGO-2460 - @Field annotation behaviour changed.
|
||||
* DATAMONGO-2459 - Update Documentation of Reactive Repositories to mention usage of PageRequest.
|
||||
* DATAMONGO-2457 - Reference documentation: Text does not match with code example.
|
||||
* DATAMONGO-2456 - Release 3.0 M3 (Neumann).
|
||||
* DATAMONGO-2449 - Add aggregation options parameters to @Aggregation annotation.
|
||||
* DATAMONGO-2427 - Switch to 4.0-beta1 MongoDB driver.
|
||||
* DATAMONGO-2417 - Typesafe Extension Function for ReactiveFindOperation.FindDistinct.
|
||||
* DATAMONGO-2406 - Allow Mono<Void> as return type for derived deleteBy queries.
|
||||
* DATAMONGO-2400 - Read/write converters not working.
|
||||
* DATAMONGO-2365 - Parameter hint in Query#hint is not index name.
|
||||
* DATAMONGO-2249 - Query hint leads to error when executed via reactive template.
|
||||
* DATAMONGO-2079 - MappingMongoConverter cannot be proxied because it implements the package-private ValueResolver interface.
|
||||
* DATAMONGO-1997 - Add support to return the single deleted item for a deleteBy query method.
|
||||
|
||||
|
||||
Changes in version 3.0.0.M2 (2020-01-17)
|
||||
----------------------------------------
|
||||
* DATAMONGO-2454 - Release 3.0 M2 (Neumann).
|
||||
|
||||
|
||||
Changes in version 3.0.0.M1 (2020-01-16)
|
||||
----------------------------------------
|
||||
* DATAMONGO-2451 - Value of sort direction converted to String for id fields (query, index creation).
|
||||
* DATAMONGO-2450 - Bulk Operations do not support filterArray in update operations.
|
||||
* DATAMONGO-2448 - Bump Version to 3.0.
|
||||
* DATAMONGO-2447 - Upgrade MongoDB Drivers to 3.12.0 and 1.13.0.
|
||||
* DATAMONGO-2444 - Update copyright years to 2020.
|
||||
* DATAMONGO-2442 - Cond.thenValueOf(String fieldReference) does not concat fieldRef with "$" prefix.
|
||||
* DATAMONGO-2440 - Unable to use MongoTemplate to perform query with 'in' condition by field annotated with @Field(targetType = FieldType.OBJECT_ID).
|
||||
* DATAMONGO-2437 - Grouping after aggregation returns NULL _id when mapping to a class with compound key.
|
||||
* DATAMONGO-2430 - Upgrade to mongo-java-driver 3.11.2.
|
||||
* DATAMONGO-2423 - @NonNullApi restricts update with null.
|
||||
* DATAMONGO-2418 - Application Context Doesn't start with @Query.
|
||||
* DATAMONGO-2414 - ReactiveGridFsResource.getDownloadStream(…) hang if completion happens on event loop.
|
||||
* DATAMONGO-2410 - Using BasicDBObject as an entity caused java.lang.ClassCastException in runtime.
|
||||
* DATAMONGO-2409 - Extension Function ReactiveFindOperation.DistinctWithProjection.asType() has wrong return type.
|
||||
* DATAMONGO-2403 - ReactiveStringBasedAggregation / AggregationUtils fails on NPE because source or value is null.
|
||||
* DATAMONGO-2399 - Upgrade to mongo-java-driver 3.11.1.
|
||||
* DATAMONGO-2394 - nearSphere query wrongly generated with radian parameter instead of meters.
|
||||
* DATAMONGO-2393 - Reading large file from ReactiveGridFsTemplate causes a stackoverflow and the code to hang.
|
||||
* DATAMONGO-2392 - Reading GridFS files written with old api and custom id fails on ReactiveGridFsTemplate.
|
||||
* DATAMONGO-2390 - Add maxTimeMS to AggregationOptions.
|
||||
* DATAMONGO-2388 - IndexOperations.getIndexInfo() fails for index that has partialFilterExpression containing DBRef.
|
||||
* DATAMONGO-2385 - Unnecessary null checks in MongoConverters.
|
||||
* DATAMONGO-2383 - Release 3.0 M1 (Neumann).
|
||||
* DATAMONGO-2370 - Add support for $round aggregation expression.
|
||||
* DATAMONGO-2331 - Add support for Aggregations in Update.
|
||||
* DATAMONGO-2059 - Replace usage of deprecated collection.count() with collection.countDocuments().
|
||||
* DATAMONGO-765 - Add support for paging and sorting on GridFSTemplate.
|
||||
|
||||
|
||||
Changes in version 2.2.4.RELEASE (2020-01-15)
|
||||
---------------------------------------------
|
||||
* DATAMONGO-2451 - Value of sort direction converted to String for id fields (query, index creation).
|
||||
@@ -2851,3 +2930,8 @@ Repository
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Data MongoDB 2.2.4
|
||||
Spring Data MongoDB 2.2.5
|
||||
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
||||
|
||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||
@@ -10,3 +10,4 @@ code for the these subcomponents is subject to the terms and
|
||||
conditions of the subcomponent's license, as noted in the LICENSE file.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user