DATAMONGO-2059 - Document count helper restrictions for geo commands inside of transactions.
This commit is contained in:
@@ -297,6 +297,7 @@ error occurs here.
|
||||
<3> An error outside the transaction flow has no affect on the previous transactional execution.
|
||||
====
|
||||
|
||||
[[mongo.transactions.behavior]]
|
||||
== Special behavior inside transactions
|
||||
|
||||
Inside transactions, MongoDB server has a slightly different behavior.
|
||||
@@ -321,6 +322,14 @@ The server responds with _error 50851_ when issuing a `count` command inside of
|
||||
Once `MongoTemplate` detects an active transaction, all exposed `count()` methods are converted and delegated to the
|
||||
aggregation framework using `$match` and `$count` operators, preserving `Query` settings, such as `collation`.
|
||||
|
||||
Restrictions apply when using geo commands inside of the aggregation count helper. The following operators cannot be used and must be replaced with a different operator:
|
||||
|
||||
* `$where` -> `$expr`
|
||||
* `$near` -> `$geoWithin` with `$center`
|
||||
* `$nearSphere` -> `$geoWithin` with `$centerSphere`
|
||||
|
||||
Queries using `Criteria.near(…)` and `Criteria.nearSphere(…)` must be rewritten to `Criteria.within(…)` respective `Criteria.withinSphere(…)`. Same applies for the `near` query keyword in repository query methods that must be changed to `within`. See also MongoDB JIRA ticket https://jira.mongodb.org/browse/DRIVERS-518[DRIVERS-518] for further reference.
|
||||
|
||||
The following snippet shows `count` usage inside the session-bound closure:
|
||||
|
||||
====
|
||||
|
||||
@@ -1201,6 +1201,8 @@ template.query(Person.class) <1>
|
||||
|
||||
MongoDB supports GeoSpatial queries through the use of operators such as `$near`, `$within`, `geoWithin`, and `$nearSphere`. Methods specific to geospatial queries are available on the `Criteria` class. There are also a few shape classes (`Box`, `Circle`, and `Point`) that are used in conjunction with geospatial related `Criteria` methods.
|
||||
|
||||
NOTE: Using GeoSpatial queries requires attention when used within MongoDB transactions, see <<mongo.transactions.behavior>>.
|
||||
|
||||
To understand how to perform GeoSpatial queries, consider the following `Venue` class (taken from the integration tests and relying on the rich `MappingMongoConverter`):
|
||||
|
||||
[source,java]
|
||||
@@ -3083,4 +3085,4 @@ class GridFsClient {
|
||||
|
||||
`GridFsOperations` extends `ResourcePatternResolver` and lets the `GridFsTemplate` (for example) to be plugged into an `ApplicationContext` to read Spring Config files from MongoDB database.
|
||||
|
||||
include::change-streams.adoc[]
|
||||
include::change-streams.adoc[]
|
||||
|
||||
Reference in New Issue
Block a user