DATAMONGO-1761 - Add domain type mapping, reactive/fluent interface operations and Kotlin extensions.

Add rename and add methods to MongoOperations.
Map query, and use execute method to run errors through the execption translator. Add Javadoc and missing issue references.
Move to assertJ.

Also add fluent and reactive api counterpart and fix BsonValue to plain java Object / domain Type conversion.
Provide Kotlin extensions for operations added.

Original pull request: #494.
Related pull request: #514.
This commit is contained in:
Christoph Strobl
2017-10-30 14:20:53 +01:00
committed by Mark Paluch
parent c9f3a52dc0
commit 45fa1e50f9
26 changed files with 1452 additions and 48 deletions

View File

@@ -1087,6 +1087,44 @@ The query methods need to specify the target type T that will be returned and th
* *find* Map the results of an ad-hoc query on the collection to a List of the specified type.
* *findAndRemove* Map the results of an ad-hoc query on the collection to a single instance of an object of the specified type. The first document that matches the query is returned and also removed from the collection in the database.
[[mongo-template.query.distinct]]
=== Query distinct values
MongoDB allows obtaining distinct field values for a single field. The stored values do not have to have the same data type to be considered, nor is the feature limited to simple types.
However when retrieving distinct values the actual result type does matter for the sake of conversion.
.Retrieving distinct values
====
[source,java]
----
template.query(Person.class) <1>
.distinct("lastname") <2>
.all(); <3>
---
<1> Query the collection of `Person`.
<2> Select _distinct_ values of the `lastname` field. The fieldname will be mapped according to the domain types property declaration, taking potential `@Field` annotations into account.
<3> Retrieve all distinct values as `List` of `Object` due to no explicit result type specification.
====
Retrieving distinct values into a `Collection` of `Object.class` is the most flexible way as it will try to determine the property value of the domain type converting results to the desired type or mapping `Document` structures.
Sometimes, when all values of the desired field are fixed to a certain type, it is more convenient to directly obtain a correctly typed `Collection`
.Retrieving strongly typed distinct values
====
[source,java]
----
template.query(Person.class) <1>
.distinct("lastname") <2>
.as(String.class) <3>
.all(); <4>
---
<1> Query the collection of `Person`.
<2> Select _distinct_ values of the `lastname` field. The fieldname will be mapped according to the domain types property declaration, taking potential `@Field` annotations into account.
<3> Retrieved values will be converted into the desired target type. In this case `String`. It would also be possible to map the values to a more complex type if the stored field contains a document.
<4> Retrieve all distinct values as a `List` of `String`. Throws a `DataAccessException` if the type cannot be converted into the desired target type.
===
[[mongo.geospatial]]
=== GeoSpatial Queries