Use case · CRM
A CRM that fits in one database.
Contacts, companies, deals, activities, search, audit history, automation, and reports are all documents. NonoDB keeps them together — without a database cluster, a separate search service, or a message broker.
Why a CRM is a document problem
CRM data is rarely a fixed table. One team needs custom lead fields, another stores partner tiers, and every customer wants a different pipeline. The records are naturally documents; the hard parts are search, timelines, audit, automation, and reporting.
Flexible records
Keep custom fields, nested addresses, tags, and imported data without a migration for every change.
Fast screens
Indexes make contact lookup, owner lists, pipeline stages, and recent activity fast.
Reliable automation
Write data and its event together, then let workers send email, sync calendars, or call webhooks.
One operational footprint
Search, SQL, history, backups, replication, auth, and a GUI are already in the same binary.
CRM feature map
Each row is a CRM need mapped to a NonoDB capability. Technical details live in the documentation; this is the product-level view.
| CRM need | NonoDB feature | What you get |
|---|---|---|
| Contact and company profiles | JSON documents | Custom fields per team or customer without schema migrations. |
| Fast contact lookup | Compound and unique indexes | Find by tenant, owner, email, or company — and stop duplicate emails. |
| Typo-tolerant search | Fuzzy index | “Kowalsky” still finds “Kowalski”. |
| Search across notes | BM25 text index | Rank contacts by relevance across a denormalized search_text field. |
| Pipeline views | Index on tenant_id + stage + updated_at | Fast stage boards and “recently changed” lists. |
| Activity timeline | Append-only activities collection + index | Contact 360 without unbounded arrays inside a contact. |
| Audit and undo | Per-collection document history | See prior versions and restore a bad edit. |
| Automation | Transactional outbox events + workers | Sync email, enrich leads, send webhooks, and retry failures. |
| Live dashboards | Watch and live subscriptions | Push won-deal alerts and dashboard updates without polling. |
| Reporting | SQL and aggregation | Pipeline value, win rate, and activity volume. |
| Multi-tenant SaaS | tenant_id plus vault collections | Tenant isolation in queries; per-tenant encryption for sensitive payloads. |
| Existing integrations | MongoDB wire endpoint | Use PyMongo, Node.js, or Go where the app stays inside the supported subset. |
| Day-two operations | Backups, replication, GUI | Restore, fail over, and support the system without extra tools. |
A data model that stays flexible
Start with four collections: contacts, companies, deals, and activities. Add tasks and the _events outbox as the product grows. Use references for records that change independently, and embed only small, bounded objects.
| Collection | Purpose | Useful fields |
|---|---|---|
| contacts | People and leads. | name, email, phone, company_id, owner_id, lifecycle, tags, custom, search_text, updated_at |
| companies | Accounts and organizations. | name, domain, industry, size, owner_id, tenant_id |
| deals | Pipeline and revenue. | title, contact_id, company_id, stage, amount, currency, close_date, owner_id, updated_at |
| activities | Calls, emails, notes, meetings. | contact_id, deal_id, type, subject, body, due_at, completed_at, owner_id, created_at |
| tasks | Follow-ups and reminders. | assignee_id, title, due_at, status, related_to, tenant_id |
| _events | Transactional outbox. | type, doc_id, payload, created_at |
search_text value from the contact name, company, email, and note snippets in your application, then index that one field. This keeps BM25 fast and predictable.Core CRM workflows
1. Make contact lookup instant
The contact list is the most-used screen in most CRMs. Index the fields that drive it, enforce one email per tenant, and add fuzzy search for duplicate detection.
{"op":"create_indexes","coll":"contacts","indexes":[
{"fields":["tenant_id","email"],"unique":true},
{"fields":["tenant_id","owner_id","updated_at"]},
{"fields":["tenant_id","company_id"]}
]}{"op":"create_fuzzy_index","coll":"contacts","field":"name"}
{"op":"create_text_index","coll":"contacts","field":"search_text"}{"op":"find","coll":"contacts",
"filter":{"tenant_id":"acme","owner_id":"u_42"},
"sort":[["updated_at",-1]],
"limit":50}{"op":"fuzzy","coll":"contacts","field":"name",
"query":"Kowalsky","max_distance":2,
"filter":{"tenant_id":"acme"},"limit":5}2. Build the pipeline board
A pipeline is a filtered, sorted list of deals. A compound index ontenant_id, stage, and updated_atserves the common board view; moving a deal is one atomic update.
{"op":"find","coll":"deals",
"filter":{"tenant_id":"acme",
"stage":{"$in":["qualified","proposal","negotiation"]}},
"sort":[["updated_at",-1]],
"limit":100}{"op":"update","coll":"deals",
"filter":{"_id":"d_123","tenant_id":"acme"},
"update":{"$set":{"stage":"won"},
"$currentDate":{"updated_at":true}}}3. Show a contact timeline and keep an audit trail
Do not grow an unbounded activity array inside a contact. Append activities as documents and query by contact and time. Enable history for deals or contacts that need an audit trail and undo.
{"op":"find","coll":"activities",
"filter":{"tenant_id":"acme","contact_id":"c_123"},
"sort":[["created_at",-1]],
"limit":50}{"op":"set_collection_history","coll":"deals","max_versions":50}
{"op":"history","coll":"deals","id":"d_123","limit":20,"include_docs":true}4. Report on pipeline value
Use aggregation for application screens and SQL for reports. The same documents serve both; there is no nightly export to a reporting database.
{"op":"aggregate","coll":"deals","pipeline":[
{"$match":{"tenant_id":"acme","stage":{"$ne":"lost"}}},
{"$group":{"_id":"$stage",
"value":{"$sum":"$amount"},
"deals":{"$sum":1}}},
{"$sort":{"value":-1}}
]}SELECT stage, COUNT(*) AS deals, SUM(amount) AS value
FROM deals
WHERE tenant_id = 'acme'
GROUP BY stage
ORDER BY value DESC;Automation without a second system
Most CRM automation is a reaction to a data change: a deal moved to won, a lead was assigned, an email arrived. NonoDB uses the transactional outbox pattern so the data change and its event commit together.
{"op":"set_collection_events","coll":"deals",
"enabled":true,"fields":["stage","amount","owner_id"]}A worker or webhook consumer then watches the _eventscollection, processes each event, and stores its own checkpoint. Delivery is at-least-once, so make handlers idempotent.
{"op":"watch","coll":"_events",
"types":["deals.update"],
"filter":{"payload.after.stage":"won"},
"after":"01J..."}For a live dashboard or a “won deal” notification, use a connection-scoped live subscription. It pushes matching changes without writing to the outbox and without polling.
{"op":"watch","coll":"deals","mode":"live",
"filter":{"stage":"won"},"ops":["update"],
"heartbeat_ms":10000}Multi-tenant CRM and security
Put tenant_id in every document and every main index. That is the simplest isolation model and keeps tenant-scoped queries fast.
For sensitive notes, credentials, or personal data that must be encrypted at rest, use a vault collection with per-tenant keys. Be deliberate: vault collections trade away secondary indexes, search, sorting, and aggregation. Keep searchable CRM records in standard collections and move only the sensitive payloads to vault.
Where another tool fits better
- Do not store thousands of activities inside one contact document. Use an append-only activities collection.
- Do not expect SQL joins. Use the aggregation
$lookupstage when a screen needs related records. - Do not use a vault collection for fields you need to search, sort, or aggregate.
- Do not use TTL for deals or tasks. Use workers for reminders; keep TTL for sessions, invites, and temporary exports.
- Do not assume exactly-once event delivery. Design handlers to be idempotent.
Ship the CRM, not the infrastructure.