DATAMONGO-1245 - Initial documentation for Query by Example.
Adopt changes from query by example API refactoring. Related tickets: DATACMNS-810. Original pull request: #341.
This commit is contained in:
committed by
Oliver Gierke
parent
693f5ddf6e
commit
5a78d99af0
@@ -1,5 +1,5 @@
|
||||
= Spring Data MongoDB - Reference Documentation
|
||||
Mark Pollack; Thomas Risberg; Oliver Gierke; Costin Leau; Jon Brisbin; Thomas Darimont; Christoph Strobl
|
||||
Mark Pollack; Thomas Risberg; Oliver Gierke; Costin Leau; Jon Brisbin; Thomas Darimont; Christoph Strobl; Mark Paluch
|
||||
:revnumber: {version}
|
||||
:revdate: {localdate}
|
||||
:toc:
|
||||
|
||||
@@ -1330,6 +1330,10 @@ TextQuery.searching(new TextCriteria().matching("\"coffee cake\""));
|
||||
TextQuery.searching(new TextCriteria().phrase("coffee cake"));
|
||||
----
|
||||
|
||||
include::../{spring-data-commons-docs}/query-by-example.adoc[]
|
||||
include::query-by-example.adoc[]
|
||||
|
||||
|
||||
[[mongo.mapreduce]]
|
||||
== Map-Reduce Operations
|
||||
|
||||
|
||||
71
src/main/asciidoc/reference/query-by-example.adoc
Normal file
71
src/main/asciidoc/reference/query-by-example.adoc
Normal file
@@ -0,0 +1,71 @@
|
||||
[[query.by.example.execution]]
|
||||
=== Executing Example
|
||||
|
||||
.Query by Example using a Repository
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
public interface PersonRepository extends QueryByExampleExecutor<Person> {
|
||||
|
||||
}
|
||||
|
||||
public class PersonService {
|
||||
|
||||
@Autowired PersonRepository personRepository;
|
||||
|
||||
public List<Person> findPeople(Person probe) {
|
||||
return personRepository.findAll(Example.of(probe));
|
||||
}
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
An `Example` containing an untyped `ExampleSpec` uses the Repository type and its collection name. Typed `ExampleSpec` use their type as result type and the collection name from the Repository.
|
||||
|
||||
NOTE: When including `null` values in the `ExampleSpec` Spring Data Mongo uses embedded document matching instead of dot notation property matching. This forces exact document matching for all property values and the property order in the embedded document.
|
||||
|
||||
Spring Data MongoDB provides support for the following matching options:
|
||||
|
||||
[cols="1,2", options="header"]
|
||||
.`StringMatcher` options
|
||||
|===
|
||||
| Matching
|
||||
| Logical result
|
||||
|
||||
| `DEFAULT` (case-sensitive)
|
||||
| `{"firstname" : firstname}`
|
||||
|
||||
| `DEFAULT` (case-insensitive)
|
||||
| `{"firstname" : { $regex: firstname, $options: 'i'}}`
|
||||
|
||||
| `EXACT` (case-sensitive)
|
||||
| `{"firstname" : { $regex: /^firstname$/}}`
|
||||
|
||||
| `EXACT` (case-insensitive)
|
||||
| `{"firstname" : { $regex: /^firstname$/, $options: 'i'}}`
|
||||
|
||||
| `STARTING` (case-sensitive)
|
||||
| `{"firstname" : { $regex: /^firstname/}}`
|
||||
|
||||
| `STARTING` (case-insensitive)
|
||||
| `{"firstname" : { $regex: /^firstname/, $options: 'i'}}`
|
||||
|
||||
| `ENDING` (case-sensitive)
|
||||
| `{"firstname" : { $regex: /firstname$/}}`
|
||||
|
||||
| `ENDING` (case-insensitive)
|
||||
| `{"firstname" : { $regex: /firstname$/, $options: 'i'}}`
|
||||
|
||||
| `CONTAINING` (case-sensitive)
|
||||
| `{"firstname" : { $regex: /.\*firstname.*/}}`
|
||||
|
||||
| `CONTAINING` (case-insensitive)
|
||||
| `{"firstname" : { $regex: /.\*firstname.*/, $options: 'i'}}`
|
||||
|
||||
| `REGEX` (case-sensitive)
|
||||
| `{"firstname" : { $regex: /firstname/}}`
|
||||
|
||||
| `REGEX` (case-insensitive)
|
||||
| `{"firstname" : { $regex: /firstname/, $options: 'i'}}`
|
||||
|
||||
|===
|
||||
Reference in New Issue
Block a user