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

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

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: None
    • Labels:
    • $i18n.getText("admin.common.words.hide")
      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
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } 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

      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
      

       

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            scott.lhommedieu@mongodb.com Scott L'Hommedieu (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: