Helpers#

class quart_mongo.helpers.BSONObjectIdConverter(map: Map, *args: t.Any, **kwargs: t.Any)#

A simple converter for the RESTful URL routing system of Quart.

Valid object ID strings are converted into bson.objectid.ObjectId objects; invalid strings result in a 404 error. The converter is automatically registered by the initialization of Mongo with keyword ObjectId. The BSONObjectIdConverter is automatically installed on the Mongo instance at creation time.

to_python(value: str) ObjectId#

Converts a string value to an ObjectId.

Parameters:

value – The value to convert.

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

  • if an InvaildId is raised by ObjectId with a 404 error code.

to_url(value: Any) str#

Converts a value to a URL string.

class quart_mongo.helpers.MongoJSONProvider(app: Quart)#

A subclass of quart.json.provider.DefaultJSONProvider that can handle MongoDB type objects and Odmantic Model classes. It can also handle Pydantic type models as well, which is for quart_schema.

mongo_json(object_: Any) Any#

Handles JSON serialization for MongoDB.

default(object_: Any) Any#

Serialize MongoDB objects and pydantic types as well as the defaults.