Wrappers#

class quart_mongo.wrappers.AIOMotorCollection(database: AIOMotorDatabase, name: str, codec_options: CodecOptions | None = None, read_preference: _ServerMode | None = None, write_concern: WriteConcern | None = None, read_concern: ReadConcern | None = None, _delegate=None)#

Subclass of the AsyncIOMotorCollection with helpers.

async find_one_or_404(*args, **kwargs) Dict#

Find a single document or raise a 404 with the browser.

This function is like AsyncIOMotorCollection.Collection.find_one, but rather than returning None. It will raise a 404 error (Not Found HTTP status) on the request.

Parameters:
  • args – Arguments to be passed to AsyncIOMotorCollection.Collection.find_one.

  • kwargs – Extra arguments to be passed to AsyncIOMotorCollection.Collection.find_one.

class quart_mongo.wrappers.AIOMotorDatabase(client: AIOMotorClient, name: str, **kwargs)#

Subclass of AsyncIOMotorDatabase.

Returns instances AsyncMotorCollection instead of native AsyncIOMotorCollection when accessed with dot notation.

Parameters:
  • client – An instance of the Motor client to use to connect to the database.

  • name – The name of the database.

  • kwargs – Extra arguments to be passed to the database.

class quart_mongo.wrappers.AIOEngine(client: AsyncIOMotorClient | None = None, database: str = 'test')#

Subclass of the :class`~Odmantic.AIOEngine` object, which is responsible for handling database operations with MongoDB in an asynchronous way using Motor.

The purpose of this subclass is to add the function :func::AIOEngine.find_one_or_404.

async find_one_or_404(model: Model, *args, **kwargs) Model#

Find a single document or raise a 404 with the browser.

This function is like find_one(), but rather than returning None. It will raise a 404 error (Not Found HTTP status) on the request.

Parameters:
  • model – The Model to use to find the model.

  • args – Arguments to pass to find_one.

  • kwargs – Extra arguments to pass to find_one.

Raises:
  • HTTPException – Uses quart.abort to raises this exception if

  • there is not entry found in the database. This will raise a 404

  • error code with the browser.

class quart_mongo.wrappers.AIOMotorClient(*args, **kwargs)#

Subclass of AsyncIOMotorClient.

Returns instances of Quart-Mongo AIOMotorDatabase instead of native AIOMotorDatabase. AIOEngine instead of native AIOEngine.

motor(name: str) AIOMotorDatabase#

Returns an instance of AIOMotorDatabase.

odm(name: str) AIOEngine#

Returns an instance of AIOEngine.