Skip to content

Commit bc0a2df

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-1179 - Update reference documentation.
Added new-features section. Updated links and requirements. Added section for GeoJSON support. Updated Script Operations section. Added return type Stream to repositories section. Updated keyword list. Original pull request: spring-projects#281.
1 parent 7e50fd8 commit bc0a2df

File tree

5 files changed

+150
-18
lines changed

5 files changed

+150
-18
lines changed

src/main/asciidoc/index.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ toc::[]
1515
include::preface.adoc[]
1616

1717
:leveloffset: +1
18+
include::new-features.adoc[]
1819
include::{spring-data-commons-docs}/repositories.adoc[]
1920
:leveloffset: -1
2021

src/main/asciidoc/new-features.adoc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[new-features]]
2+
= New & Noteworthy
3+
4+
[[new-features.1-7-0]]
5+
== What's new in Spring Data MongoDB 1.7
6+
7+
* Assert compatibility with MongoDB 3.0 and MongoDB Java Driver 3-beta3 (see: <<mongo.mongo-3>>).
8+
* Support JSR-310 and ThreeTen back-port date/time types.
9+
* Allow `Stream` as query method return type (see: <<mongodb.repositories.queries>>).
10+
* Added http://geojson.org/[GeoJSON] support in both domain types and queries (see: <<mongo.geo-json>>).
11+
* `QueryDslPredicateExcecutor` now supports `findAll(OrderSpecifier<?>… orders)`.
12+
* Support calling JavaScript functions via <<mongo.server-side-scripts>>.
13+
* Improve support for `CONTAINS` keyword on collection like properties.
14+
* Support for `$bit`, `$mul` and `$position` operators to `Update`.
15+

src/main/asciidoc/preface.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ The jumping off ground for learning about MongoDB is http://www.mongodb.org/[www
3030
[[requirements]]
3131
== Requirements
3232

33-
Spring Data MongoDB 1.x binaries requires JDK level 6.0 and above, and http://spring.io/docs[Spring Framework] 3.2.x and above.
33+
Spring Data MongoDB 1.x binaries requires JDK level 6.0 and above, and http://spring.io/docs[Spring Framework] 4.0.x and above.
3434

35-
In terms of document stores, http://www.mongodb.org/[MongoDB] at least 2.4, preferably version 2.6.
35+
In terms of document stores, http://www.mongodb.org/[MongoDB] at least 2.6.
3636

3737
== Additional Help Resources
3838

@@ -46,12 +46,12 @@ There are a few support options available:
4646
[[get-started:help:community]]
4747
==== Community Forum
4848

49-
Spring Data on Stackoverflow http://stackoverflow.com/questions/tagged/spring-data[Stackoverflow ] is a tag for all Spring Data (not just Document) users to share information and help each other. Note that registration is needed *only* for posting.
49+
Spring Data on Stackoverflow http://stackoverflow.com/questions/tagged/spring-data[Stackoverflow] is a tag for all Spring Data (not just Document) users to share information and help each other. Note that registration is needed *only* for posting.
5050

5151
[[get-started:help:professional]]
5252
==== Professional Support
5353

54-
Professional, from-the-source support, with guaranteed response time, is available from http://gopivotal.com/[Pivotal Sofware, Inc.], the company behind Spring Data and Spring.
54+
Professional, from-the-source support, with guaranteed response time, is available from http://pivotal.io/[Pivotal Sofware, Inc.], the company behind Spring Data and Spring.
5555

5656
[[get-started:up-to-date]]
5757
=== Following Development

src/main/asciidoc/reference/mongo-repositories.adoc

+27-5
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,22 @@ Most of the data access operations you usually trigger on a repository result a
134134
----
135135
public interface PersonRepository extends PagingAndSortingRepository<Person, String> {
136136
137-
List<Person> findByLastname(String lastname);
137+
List<Person> findByLastname(String lastname); <1>
138138
139-
Page<Person> findByFirstname(String firstname, Pageable pageable);
139+
Page<Person> findByFirstname(String firstname, Pageable pageable); <2>
140140
141-
Person findByShippingAddresses(Address address);
141+
Person findByShippingAddresses(Address address); <3>
142+
143+
Stream<Person> findAllBy(); <4>
142144
}
143145
----
146+
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
147+
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
148+
<3> Shows that you can query based on properties which are not a primitive type.
149+
<4> Uses a Java 8 `Stream` which reads and converts individual elements while iterating the stream.
144150
====
145151

146-
The first method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of`{"lastname" : lastname}`. The second example shows how pagination is applied to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly. The third examples shows that you can query based on properties which are not a primitive type.
152+
147153

148154
NOTE: Note that for version 1.0 we currently don't support referring to parameters that are mapped as `DBRef` in the domain class.
149155

@@ -154,6 +160,10 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
154160
| Sample
155161
| Logical result
156162

163+
| `After`
164+
| `findByBirthdateAfter(Date date)`
165+
| `{"birthdate" : {"$gt" : date}}`
166+
157167
| `GreaterThan`
158168
| `findByAgeGreaterThan(int age)`
159169
| `{"age" : {"$gt" : age}}`
@@ -162,6 +172,10 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
162172
| `findByAgeGreaterThanEqual(int age)`
163173
| `{"age" : {"$gte" : age}}`
164174

175+
| `Before`
176+
| `findByBirthdateBefore(Date date)`
177+
| `{"birthdate" : {"$lt" : date}}`
178+
165179
| `LessThan`
166180
| `findByAgeLessThan(int age)`
167181
| `{"age" : {"$lt" : age}}`
@@ -190,10 +204,18 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
190204
| `findByFirstnameNull()`
191205
| `{"firstname" : null}`
192206

193-
| `Like`
207+
| `Like`, `StartingWith`, `EndingWith`
194208
| `findByFirstnameLike(String name)`
195209
| `{"firstname" : name} ( name as regex)`
196210

211+
| `Containing` on String
212+
| `findByFirstnameContaining(String name)`
213+
| `{"firstname" : name} (name as regex)`
214+
215+
| `Containing` on Collection
216+
| `findByAddressesContaining(Address address)`
217+
| `{"addresses" : { "$in" : address}}`
218+
197219
| `Regex`
198220
| `findByFirstnameRegex(String firstname)`
199221
| `{"firstname" : {"$regex" : firstname }}`

src/main/asciidoc/reference/mongodb.adoc

+103-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For most tasks you will find yourself using `MongoTemplate` or the Repository su
2121
[[mongodb-getting-started]]
2222
== Getting Started
2323

24-
Spring MongoDB support requires MongoDB 1.4 or higher and Java SE 5 or higher. The latest production release (2.4.9 as of this writing) is recommended. An easy way to bootstrap setting up a working environment is to create a Spring based project in http://spring.io/tools/sts[STS].
24+
Spring MongoDB support requires MongoDB 2.6 or higher and Java SE 6 or higher. An easy way to bootstrap setting up a working environment is to create a Spring based project in http://spring.io/tools/sts[STS].
2525

2626
First you need to set up a running Mongodb server. Refer to the http://docs.mongodb.org/manual/core/introduction/[Mongodb Quick Start guide] for an explanation on how to startup a MongoDB instance. Once installed starting MongoDB is typically a matter of executing the following command: `MONGO_HOME/bin/mongod`
2727

@@ -38,7 +38,7 @@ Then add the following to pom.xml dependencies section.
3838
<dependency>
3939
<groupId>org.springframework.data</groupId>
4040
<artifactId>spring-data-mongodb</artifactId>
41-
<version>1.4.1.RELEASE</version>
41+
<version>1.7.0.RELEASE</version>
4242
</dependency>
4343
4444
</dependencies>
@@ -48,7 +48,7 @@ Also change the version of Spring in the pom.xml to be
4848

4949
[source,xml]
5050
----
51-
<spring.framework.version>3.2.8.RELEASE</spring.framework.version>
51+
<spring.framework.version>4.0.9.RELEASE</spring.framework.version>
5252
----
5353

5454
You will also need to add the location of the Spring Milestone repository for maven to your pom.xml which is at the same level of your <dependencies/> element
@@ -162,7 +162,7 @@ Even in this simple example, there are few things to take notice of
162162
[[mongo.examples-repo]]
163163
== Examples Repository
164164

165-
There is an https://github.com/spring-projects/spring-data-document-examples[github repository with several examples] that you can download and play around with to get a feel for how the library works.
165+
There is an https://github.com/spring-projects/spring-data-examples[github repository with several examples] that you can download and play around with to get a feel for how the library works.
166166

167167
[[mongodb-connectors]]
168168
== Connecting to MongoDB with Spring
@@ -1156,6 +1156,96 @@ As you can see we use the `NearQuery` builder API to set up a query to return al
11561156

11571157
The geo near operations return a `GeoResults` wrapper object that encapsulates `GeoResult` instances. The wrapping `GeoResults` allows to access the average distance of all results. A single `GeoResult` object simply carries the entity found plus its distance from the origin.
11581158

1159+
[[mongo.geo-json]]
1160+
=== GeoJSON Support
1161+
1162+
MongoDB supports http://geojeson.org/[GeoJSON] and simple (legacy) coordinate pairs for geospatial data. Those formats can both be used for storing as well as querying data.
1163+
1164+
NOTE: Please refer to the http://docs.mongodb.org/manual/core/2dsphere/#geospatial-indexes-store-geojson/[MongoDB manual on GeoJSON support] to learn about requirements and restrictions.
1165+
1166+
==== GeoJSON types in domain classes
1167+
1168+
Usage of http://geojeson.org/[GeoJSON] types in domain classes is straight forward. The `org.springframework.data.mongodb.core.geo` package contains types like `GeoJsonPoint`, `GeoJsonPolygon` and others. Those are extensions to the existing `org.springframework.data.geo` types.
1169+
1170+
====
1171+
[source,java]
1172+
----
1173+
public class Store {
1174+
1175+
String id;
1176+
1177+
/**
1178+
* location is stored in GeoJSON format.
1179+
* {
1180+
* "type" : "Point",
1181+
* "coordinates" : [ x, y ]
1182+
* }
1183+
*/
1184+
GeoJsonPoint location;
1185+
}
1186+
----
1187+
====
1188+
1189+
==== GeoJSON types in repository query methods
1190+
1191+
Using GeoJSON types as repository query parameters forces usage of the `$geometry` operator when creating the query.
1192+
1193+
====
1194+
[source,java]
1195+
----
1196+
public interface StoreRepository extends CrudRepository<Store, String> {
1197+
1198+
List<Store> findByLocationWithin(Polygon polygon); <1>
1199+
1200+
}
1201+
1202+
/*
1203+
* {
1204+
* "location": {
1205+
* "$geoWithin": {
1206+
* "$geometry": {
1207+
* "type": "Polygon",
1208+
* "coordinates": [
1209+
* [
1210+
* [-73.992514,40.758934],
1211+
* [-73.961138,40.760348],
1212+
* [-73.991658,40.730006],
1213+
* [-73.992514,40.758934]
1214+
* ]
1215+
* ]
1216+
* }
1217+
* }
1218+
* }
1219+
* }
1220+
*/
1221+
repo.findByLocationWithin( <2>
1222+
new GeoJsonPolygon(
1223+
new Point(-73.992514, 40.758934),
1224+
new Point(-73.961138, 40.760348),
1225+
new Point(-73.991658, 40.730006),
1226+
new Point(-73.992514, 40.758934))); <3>
1227+
1228+
/*
1229+
* {
1230+
* "location" : {
1231+
* "$geoWithin" : {
1232+
* "$polygon" : [ [-73.992514,40.758934] , [-73.961138,40.760348] , [-73.991658,40.730006] ]
1233+
* }
1234+
* }
1235+
* }
1236+
*/
1237+
repo.findByLocationWithin( <4>
1238+
new Polygon(
1239+
new Point(-73.992514, 40.758934),
1240+
new Point(-73.961138, 40.760348),
1241+
new Point(-73.991658, 40.730006));
1242+
----
1243+
<1> Repository method definition using the commons type allows calling it with both GeoJSON and legacy format.
1244+
<2> Use GeoJSON type the make use of `$geometry` operator.
1245+
<3> Plase note that GeoJSON polygons need the define a closed ring.
1246+
<4> Use legacy format `$polygon` operator.
1247+
====
1248+
11591249
[[mongo.textsearch]]
11601250
=== Full Text Queries
11611251

@@ -1340,17 +1430,21 @@ MongoDB allows to execute JavaScript functions on the server by either directly
13401430

13411431
=== Example Usage
13421432

1433+
====
13431434
[source,java]
13441435
----
13451436
ScriptOperations scriptOps = template.scriptOps();
13461437
1347-
ServerSideJavaScript echoScript = new ExecutableMongoScript("function(x) { return x; }");
1348-
scriptOps.execute(echoScript, "directly execute script");
1438+
ExecutableMongoScript echoScript = new ExecutableMongoScript("function(x) { return x; }");
1439+
scriptOps.execute(echoScript, "directly execute script"); <1>
13491440
1350-
scriptOps.register(new CallableMongoScript("echo", echoScript));
1351-
scriptOps.call("echo", "execute script via name");
1441+
scriptOps.register(new NamedMongoScript("echo", echoScript)); <2>
1442+
scriptOps.call("echo", "execute script via name"); <3>
13521443
----
1353-
1444+
<1> Execute the script directly without storing the function on server side.
1445+
<2> Store the script using 'echo' as its name. The given name identifies the script and allows calling it later.
1446+
<3> Execute the script with name 'echo' using the provided parameters.
1447+
====
13541448

13551449
[[mongo.group]]
13561450
== Group Operations

0 commit comments

Comments
 (0)