Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-518

Add API-level documentation for restriction of geo commands in count helpers

    XMLWordPrintable

    Details

    • Type: Task
    • Status: In Progress
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • # Replies:
      0
    • Last comment by Customer:
      false
    • Documentation Changes:
      Needed
    • Documentation Changes Summary:
      Hide
      update docs for count to reflect the limitations of geo and where. see here:
      https://docs.mongodb.com/manual/reference/operator/aggregation/match/#restrictions
      Show
      update docs for count to reflect the limitations of geo and where. see here: https://docs.mongodb.com/manual/reference/operator/aggregation/match/#restrictions
    • SERVER fixVersion:
      4.0

      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
      

       

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                scott.lhommedieu Scott L'Hommedieu (Inactive)
                Participants:
                Last commenter:
                Jeffrey Yemin
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since reply:
                  1 year, 24 weeks, 3 days ago
                  Date of 1st Reply: