You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adopt type hint assertion for existing _class field checks. Simplify test code to use Collections.singletonList instead of Arrays.asList. Replace BasicDBList with List in JavaDoc. Use type inference for DocumentTestUtils.getAsDBList to avoid casts in test code. Extend documentation.
Original pull request: spring-projects#411.
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java
+7-8
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ public void updateMapperRetainsTypeInformationForCollectionField() {
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/event/ApplicationContextEventTests.java
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mongodb.adoc
+7-5
Original file line number
Diff line number
Diff line change
@@ -666,7 +666,8 @@ When querying and updating `MongoTemplate` will use the converter to handle conv
666
666
667
667
As MongoDB collections can contain documents that represent instances of a variety of types. A great example here is if you store a hierarchy of classes or simply have a class with a property of type `Object`. In the latter case the values held inside that property have to be read in correctly when retrieving the object. Thus we need a mechanism to store type information alongside the actual document.
668
668
669
-
To achieve that the `MappingMongoConverter` uses a `MongoTypeMapper` abstraction with `DefaultMongoTypeMapper` as it's main implementation. Its default behavior is storing the fully qualified classname under `_class` inside the document for the top-level document as well as for every value if it's a complex type and a subtype of the property type declared.
669
+
To achieve that the `MappingMongoConverter` uses a `MongoTypeMapper` abstraction with `DefaultMongoTypeMapper` as it's main implementation. Its default behavior is storing the fully qualified classname under `_class` inside the document. Type hints are written for top-level documents as well as for every value if it's a complex type and a subtype of the property type declared.
670
+
670
671
671
672
.Type mapping
672
673
====
@@ -685,13 +686,14 @@ sample.value = new Person();
685
686
686
687
mongoTemplate.save(sample);
687
688
688
-
{ "_class" : "com.acme.Sample",
689
-
"value" : { "_class" : "com.acme.Person" }
689
+
{
690
+
"value" : { "_class" : "com.acme.Person" },
691
+
"_class" : "com.acme.Sample"
690
692
}
691
693
----
692
694
====
693
695
694
-
As you can see we store the type information for the actual root class persistent as well as for the nested type as it is complex and a subtype of `Contact`. So if you're now using `mongoTemplate.findAll(Object.class, "sample")` we are able to find out that the document stored shall be a `Sample` instance. We are also able to find out that the value property shall be a `Person` actually.
696
+
As you can see we store the type information as last field for the actual root class as well as for the nested type as it is complex and a subtype of `Contact`. So if you're now using `mongoTemplate.findAll(Object.class, "sample")` we are able to find out that the document stored shall be a `Sample` instance. We are also able to find out that the value property shall be a `Person` actually.
695
697
696
698
==== Customizing type mapping
697
699
@@ -1053,7 +1055,7 @@ As you can see most methods return the `Criteria` object to provide a fluent sty
1053
1055
* `Criteria` *gte* `(Object o)` Creates a criterion using the `$gte` operator
1054
1056
* `Criteria` *in* `(Object... o)` Creates a criterion using the `$in` operator for a varargs argument.
1055
1057
* `Criteria` *in* `(Collection<?> collection)` Creates a criterion using the `$in` operator using a collection
1056
-
* `Criteria` *is* `(Object o)` Creates a criterion using the `$is` operator
1058
+
* `Criteria` *is* `(Object o)` Creates a criterion using field matching (`{ key:value }`). If the specified value is a document, the order of the fields and exact equality in the document matters.
1057
1059
* `Criteria` *lt* `(Object o)` Creates a criterion using the `$lt` operator
1058
1060
* `Criteria` *lte* `(Object o)` Creates a criterion using the `$lte` operator
1059
1061
* `Criteria` *mod* `(Number value, Number remainder)` Creates a criterion using the `$mod` operator
0 commit comments