openfoodfacts_proxy.infrastructure.database
source module openfoodfacts_proxy.infrastructure.database
Functions
-
select_requested_fields — Return only the requested top-level fields from a document.
-
get_product_by_barcode — Fetch a single product by its barcode (code field) from local MongoDB.
-
search_products — Search products in local MongoDB with basic filtering.
-
ensure_indexes — Create indexes on the products collection for efficient querying.
source select_requested_fields(document: dict[str, Any], fields: str | None) → dict[str, Any]
Return only the requested top-level fields from a document.
source get_product_by_barcode(db: Database, barcode: str, *, fields: str | None = None) → dict[str, Any] | None
Fetch a single product by its barcode (code field) from local MongoDB.
source search_products(db: Database, *, code: str | None = None, product_name: str | None = None, brands: str | None = None, categories_tags: str | None = None, nutrition_grades: str | None = None, page: int = 1, page_size: int = 24, sort_by: str | None = None, fields: str | None = None) → dict[str, Any]
Search products in local MongoDB with basic filtering.
Returns a response structure compatible with the OFF API search response.
source ensure_indexes(db: Database) → None
Create indexes on the products collection for efficient querying.