Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-59674

estimatedDocumentCount does not work on views on 5.0+

    • QO 2021-09-06

      Due to the changes in DRIVERS-1437, estimatedDocumentCount no longer works on views on 5.0+. For example:

      >>> db = client.test
      >>> db.view.drop()
      >>> db.create_collection('view', viewOn='coll')
      >>> db.view.count_documents({})
      0
      >>> db.view.estimated_document_count()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 1495, in estimated_document_count
          return self.__database.client._retryable_read(
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1384, in _retryable_read
          return func(session, server, sock_info, slave_ok)
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 1484, in _cmd
          result = self._aggregate_one_result(
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 1436, in _aggregate_one_result
          result = self._command(
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 221, in _command
          return sock_info.command(
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 718, in command
          return command(self, dbname, spec, slave_ok,
        File "/Users/shane/git/mongo-python-driver/pymongo/network.py", line 158, in command
          helpers._check_command_response(
        File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 167, in _check_command_response
          raise OperationFailure(errmsg, code, response, max_wire_version)
      pymongo.errors.OperationFailure: PlanExecutor error during aggregation :: caused by :: Namespace test.view is a view, not a collection, full error: {'ok': 0.0, 'errmsg': 'PlanExecutor error during aggregation :: caused by :: Namespace test.view is a view, not a collection', 'code': 166, 'codeName': 'CommandNotSupportedOnView', '$clusterTime': {'clusterTime': Timestamp(1630345764, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}, 'operationTime': Timestamp(1630345764, 1)}
      

            Assignee:
            james.wahlin@mongodb.com James Wahlin
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved: