Use case · E-commerce
A catalog and order desk in one place.
Products, variants, categories, search, recommendations, carts, orders, and fulfilment events are documents and events. NonoDB keeps the catalog searchable and the order flow consistent without a search cluster and a message broker.
Catalogs are documents. Orders are events.
A product has optional attributes, localized text, images, variants, and category-specific fields. An order is a state machine with side effects: payment, email, stock, and fulfilment. NonoDB handles both shapes without forcing them into the same rigid table.
Product data that changes
Keep attributes, variants, and category-specific fields as documents.
Search next to stock
Text, fuzzy, and vector search read the same live documents as checkout.
One writer, clear stock
Conditional updates reserve stock without a race between checkout requests.
No dual writes
Order events commit with the order, so payment and email cannot drift.
E-commerce feature map
| Store need | NonoDB feature | What you get |
|---|---|---|
| Flexible product data | JSON documents | Different attributes per category without a migration for every field. |
| Fast catalog screens | Unique and compound indexes | Look up by SKU, category, status, price, and recency. |
| Product search | BM25 text index | Rank products by relevance across a denormalized search_text field. |
| Typo-tolerant search | Fuzzy index | “headfones” still finds “headphones”. |
| Similar products | Vector index | Exact top-K similarity for recommendations and “more like this”. |
| Variant selection | Variants collection + index | Price and stock per SKU without duplicating the whole product. |
| Cart expiry | TTL collections | Abandoned carts clean themselves up after a week. |
| Stock reservation | Atomic find_and_modify | Decrement stock only when enough units are available. |
| Order automation | Transactional outbox events | Payment, email, and fulfilment consumers react to committed changes. |
| Reporting | SQL and aggregation | Revenue by status, product, or period without an export job. |
| Multi-tenant storefronts | tenant_id plus vault collections | Workspace isolation in queries; encrypt sensitive payment metadata. |
| Existing stack | MongoDB wire endpoint | Reuse PyMongo, Node.js, or Go drivers inside the supported subset. |
| Operations | Backups, replication, GUI | Restore, fail over, and support the store from one system. |
The data model
Keep product content and SKU-level stock separate. A product page is one product plus its variants; a checkout is an order plus events.
| Collection | Purpose | Useful fields |
|---|---|---|
| products | Sellable product and searchable content. | sku, name, slug, description, search_text, category_id, brand, attributes, price, currency, status, embedding |
| variants | SKU-level price and stock. | product_id, sku, options, price, stock, barcode, tenant_id |
| categories | Navigation and breadcrumbs. | name, slug, parent_id, path, tenant_id |
| orders | Checkout and fulfilment state. | customer_id, items, total, currency, status, payment_status, shipping, created_at |
| carts | Short-lived shopping carts. | customer_id, items, updated_at, tenant_id |
| _events | Order, payment, and fulfilment events. | type, doc_id, payload, created_at |
Core store workflows
1. Make catalog screens fast
Index the fields behind category pages, SKU lookup, and price filters. Enforce one SKU per tenant for products and variants.
{"op":"create_indexes","coll":"products","indexes":[
{"fields":["tenant_id","sku"],"unique":true},
{"fields":["tenant_id","category_id","status","updated_at"]},
{"fields":["tenant_id","price"]}
]}
{"op":"create_indexes","coll":"variants","indexes":[
{"fields":["tenant_id","sku"],"unique":true},
{"fields":["tenant_id","product_id"]}
]}{"op":"find","coll":"variants",
"filter":{"tenant_id":"acme","product_id":"p_123"},
"sort":[["price",1]],
"limit":50}2. Add search and recommendations
Build one search_text field from the product name, brand, category, and description. Text search ranks it; fuzzy search handles typos. Vector search is exact top-K over the indexed field — ideal for a focused catalog, not a substitute for a dedicated billion-vector service.
{"op":"create_text_index","coll":"products","field":"search_text"}
{"op":"create_fuzzy_index","coll":"products","field":"name"}
{"op":"create_vector_index","coll":"products","field":"embedding","dims":384,"metric":"cosine"}{"op":"search","coll":"products","field":"search_text",
"query":"wireless headphones",
"filter":{"tenant_id":"acme","status":"active","category_id":"audio"},
"limit":20}{"op":"vector_search","coll":"products","field":"embedding",
"vector":[0.12,-0.03,0.44],
"filter":{"tenant_id":"acme","status":"active"},
"limit":8}3. Reserve stock safely
A conditional update decrements stock only when the requested quantity is available. If no document matches, the item is out of stock. Write the order after the reservation and reconcile abandoned reservations in a worker.
{"op":"find_and_modify","coll":"variants",
"filter":{"tenant_id":"acme","sku":"SKU-1","stock":{"$gte":2}},
"update":{"$inc":{"stock":-2}},
"new":true}4. Expire abandoned carts
Carts are temporary. Set a collection TTL for new carts and let the maintenance worker remove them. Do not use TTL for orders or inventory.
{"op":"create_collection","coll":"carts","ttl_seconds":604800}
{"op":"insert","coll":"carts",
"doc":{"_id":"cart_123","tenant_id":"acme","customer_id":"c_1",
"items":[],"updated_at":"2026-05-01T12:00:00Z"}}Order events and reporting
Enable events for order status and payment changes. Payment, email, and fulfilment consumers read the outbox and keep their own checkpoints. Delivery is at-least-once, so handlers must be idempotent.
{"op":"set_collection_events","coll":"orders",
"enabled":true,"fields":["status","payment_status"]}
{"op":"watch","coll":"_events","types":["orders.update"],
"filter":{"payload.after.payment_status":"paid"},"after":"01J..."}{"op":"aggregate","coll":"orders","pipeline":[
{"$match":{"tenant_id":"acme","status":{"$ne":"cancelled"}}},
{"$group":{"_id":"$status",
"orders":{"$sum":1},
"revenue":{"$sum":"$total"}}},
{"$sort":{"revenue":-1}}
]}Where another tool fits better
- Do not store product images or large files in documents. Keep object-store URLs and metadata.
- Do not duplicate every variant into the product document. Use a variants collection.
- Do not use TTL for orders or stock. Use TTL for carts, sessions, and temporary exports.
- Do not use a vault collection for products you need to search or sort.
- Do not treat vector search as an approximate billion-scale index; it is exact top-K over the indexed set.
Catalog, search, stock, and events in one binary.