From 9d27d2ff8e54c59f62bf5cda85c9e841e37b77f4 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 17 Aug 2018 17:23:53 +0200 Subject: [PATCH] DATAMONGO-2059 - Document count helper restrictions for geo commands inside of transactions. --- .../asciidoc/reference/client-session-transactions.adoc | 9 +++++++++ src/main/asciidoc/reference/mongodb.adoc | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/asciidoc/reference/client-session-transactions.adoc b/src/main/asciidoc/reference/client-session-transactions.adoc index 4321564e7..e27aa2d8b 100644 --- a/src/main/asciidoc/reference/client-session-transactions.adoc +++ b/src/main/asciidoc/reference/client-session-transactions.adoc @@ -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: ==== diff --git a/src/main/asciidoc/reference/mongodb.adoc b/src/main/asciidoc/reference/mongodb.adoc index 4e69bf26a..41735e475 100644 --- a/src/main/asciidoc/reference/mongodb.adoc +++ b/src/main/asciidoc/reference/mongodb.adoc @@ -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 <>. + 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[] \ No newline at end of file +include::change-streams.adoc[]