[DRIVERS-518] Add API-level documentation for restriction of geo commands in count helpers Created: 22/Jun/18  Updated: 28/Oct/23  Resolved: 05/May/20

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Scott L'Hommedieu (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: newdriver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on RUST-61 Add API-level documentation for restr... Closed
depends on CSHARP-2310 Add API-level documentation for restr... Closed
depends on CXX-1604 Add API-level documentation for restr... Closed
depends on JAVA-2893 Add API-level documentation for restr... Closed
depends on MOTOR-247 Add API-level documentation for restr... Closed
depends on NODE-1529 Add API-level documentation for restr... Closed
depends on PHPLIB-359 Document alternatives to restricted q... Closed
depends on PYTHON-1595 Add API-level documentation for restr... Closed
depends on RUBY-1370 Add API-level documentation for restr... Closed
depends on GODRIVER-478 Add API-level documentation for restr... Closed
depends on CDRIVER-2721 Add API-level documentation for restr... Closed
Related
related to DOCS-12090 new count helper restrictions Closed
Driver Compliance:
Key Status/Resolution FixVersion
NODE-1529 Fixed 3.1.0
SCALA-427 Fixed 2.4.0
PYTHON-1595 Fixed 3.7
CSHARP-2310 Fixed 2.7.0
PERL-945 Fixed 2.0.0
RUBY-1370 Fixed 2.6.0
JAVA-2893 Fixed 3.8.0
CXX-1604 Fixed 3.4.0
PHPLIB-359 Fixed 1.4.0
MOTOR-247 Fixed 2.0
GODRIVER-478 Won't Fix
CDRIVER-2721 Fixed 1.12.0
RUST-61 Done
SWIFT-415 Won't Fix

 Description   

With the deprecation of the count() and command users will be asked to move to the use of countDocuments() and estimatedDocumentCount() helpers.

The deprecation messaging in the api and deprecation warning should mention the restrictions on using the following commands/operators in the query/filter of the count and the countDocuments helpers.

restricted -> replacement:

$where -> $expr
$near -> $geoWithin with $center
$nearSphere -> $geoWithin with $centerSphere

Also note that $expr requires MongoDB 3.6+ ($geoWithin was new in MongoDB 2.4, replacing $within)

Some examples:

$where -> $expr

>>> c.legacy.where.insert_one({'_id': 1})
<pymongo.results.InsertOneResult object at 0x7f3bd73f2388>
>>> c.legacy.where.find_one({'$where': 'function() {return this._id == 1;}'})
{'_id': 1}
>>> c.legacy.where.count({'$where': 'function() {return this._id == 1;}'})
1
>>> c.legacy.where.count_documents({'$where': 'function() {return this._id == 1;}'})
Traceback (most recent call last):
...
pymongo.errors.OperationFailure: $where is not allowed in this context
>>> c.legacy.where.count_documents({'$expr': {'_id': 1}})
1

$near -> $geoWithin with $center

>>> c.geo.legacy.insert_one({'loc': [-50, 50]})
<pymongo.results.InsertOneResult object at 0x7f3bdcbeafc8>
>>> c.geo.legacy.create_index([('loc', '2d')])
'loc_2d'
>>> c.geo.legacy.find_one({'loc': {'$near': [-73, 40]}})
{'loc': [-50, 50], '_id': ObjectId('5b2ec3b49110ea19b6a54bb4')}
>>> c.geo.legacy.count({'loc': {'$near': [-73, 40]}})
1
>>> c.geo.legacy.count_documents({'loc': {'$near': [-73, 40]}})
Traceback (most recent call last):
...
pymongo.errors.OperationFailure: $geoNear, $near, and $nearSphere are not allowed in this context
>>> c.geo.legacy.count_documents({'loc': {'$geoWithin': {'$center': [[-73, 40], 30]}}})
1

$nearSphere -> $geoWithin with $centerSphere

>>> c.geo.legacy.find_one({'loc': {'$nearSphere': [-73, 40]}})
{'loc': [-50, 50], '_id': ObjectId('5b2ec3b49110ea19b6a54bb4')}
>>> c.geo.legacy.count({'loc': {'$nearSphere': [-73, 40]}})
1
>>> c.geo.legacy.count_documents({'loc': {'$nearSphere': [-73, 40]}})
Traceback (most recent call last):
...
pymongo.errors.OperationFailure: $geoNear, $near, and $nearSphere are not allowed in this context
>>> c.geo.legacy.count_documents({'loc': {'$geoWithin': {'$centerSphere': [[-73, 40], 10]}}})
1

 

 

 


Generated at Thu Feb 08 08:21:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.