def _run_command(self, command, table=None, *args, **kwargs): """Run a specific command on a given backend. :param str command: command to run. :param str table: table to use. self table if None. """ result = None try: if table is None: table = self.get_table() # get pymongo raw collection backend = self._get_backend(backend=table).collection backend_command = getattr(backend, command) result = MongoStore.hr(backend_command, *args, **kwargs) except NetworkTimeout: self.logger.warning( 'Try to run command {0}({1}) on {2} attempts left' .format(command, kwargs, backend)) except (OperationFailure, CollectionError) as of: self.logger.error(u'{0} during running command {1}({2}) of in {3}' .format(of, command, kwargs, backend)) return result
def drop(self, table=None): if table is None: collections = MongoStore.hr(self._database.collection_names, include_system_collections=False) for collection_name in collections: self.drop(table=collection_name) else: self._get_backend(backend=table).remove()
def drop(self, table=None): if table is None: collections = MongoStore.hr( self._database.collection_names, include_system_collections=False ) for collection_name in collections: self.drop(table=collection_name) else: self._get_backend(backend=table).remove()
def size(self, table=None, criteria=None, *args, **kwargs): result = 0 _backend = self._get_backend(backend=table) try: result = MongoStore.hr(self._database.command, "collstats", _backend)['size'] except Exception as ex: self.logger.warning( "Impossible to read Collection Size: {0}".format(ex)) result = None return result
def __getattr__(self, name): return MongoStore.hr(self.__pymongo_getattr__, name)
def wrapped(*args, **kwargs): """ Wrapper implementation """ return MongoStore.hr(func, *args, **kwargs)