code: def _count(self, cmd, collation=None, session=None):
          
          def _cmd(session, server, sock_info, slave_ok):
              res = self._command(
                  sock_info,
                  cmd,
                  slave_ok,
                  allowable_errors=["ns missing"],
                  codec_options=self.__write_response_codec_options,
                  read_concern=self.read_concern,
                  collation=collation,
                  session=session)
              if res.get("errmsg", "") == "ns missing":
                  return 0
              return int(res["n"])
  
          return self.__database.client._retryable_read(
              _cmd, self._read_preference_for(session), session)
docs: Internal count helper.