def count()

in modular_sdk/models/pynamodb_extension/pynamodb_to_pymongo_adapter.py [0:0]


    def count(self, model_class, hash_key=None,
              range_key_condition=None,
              filter_condition=None,
              index_name=None,
              limit=None) -> int:
        collection = self._collection_from_model(model_class)

        hash_key_name = getattr(model_class._hash_key_attribute(),
                                'attr_name', None)
        if index_name:
            hash_key_name = getattr(
                model_class._indexes[index_name]._hash_key_attribute(),
                'attr_name', None
            )

        _query = {hash_key_name: hash_key}
        if range_key_condition is not None:
            _query.update(ConditionConverter.convert(range_key_condition))

        if filter_condition is not None:
            _query.update(ConditionConverter.convert(filter_condition))

        if limit:
            return collection.count_documents(_query, limit=limit)

        return collection.count_documents(_query)