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.

ContactsPipelineActivity timelineSearchAutomationReportingMulti-tenant

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 needNonoDB featureWhat you get
Contact and company profilesJSON documentsCustom fields per team or customer without schema migrations.
Fast contact lookupCompound and unique indexesFind by tenant, owner, email, or company — and stop duplicate emails.
Typo-tolerant searchFuzzy index“Kowalsky” still finds “Kowalski”.
Search across notesBM25 text indexRank contacts by relevance across a denormalized search_text field.
Pipeline viewsIndex on tenant_id + stage + updated_atFast stage boards and “recently changed” lists.
Activity timelineAppend-only activities collection + indexContact 360 without unbounded arrays inside a contact.
Audit and undoPer-collection document historySee prior versions and restore a bad edit.
AutomationTransactional outbox events + workersSync email, enrich leads, send webhooks, and retry failures.
Live dashboardsWatch and live subscriptionsPush won-deal alerts and dashboard updates without polling.
ReportingSQL and aggregationPipeline value, win rate, and activity volume.
Multi-tenant SaaStenant_id plus vault collectionsTenant isolation in queries; per-tenant encryption for sensitive payloads.
Existing integrationsMongoDB wire endpointUse PyMongo, Node.js, or Go where the app stays inside the supported subset.
Day-two operationsBackups, replication, GUIRestore, 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.

CollectionPurposeUseful fields
contactsPeople and leads.name, email, phone, company_id, owner_id, lifecycle, tags, custom, search_text, updated_at
companiesAccounts and organizations.name, domain, industry, size, owner_id, tenant_id
dealsPipeline and revenue.title, contact_id, company_id, stage, amount, currency, close_date, owner_id, updated_at
activitiesCalls, emails, notes, meetings.contact_id, deal_id, type, subject, body, due_at, completed_at, owner_id, created_at
tasksFollow-ups and reminders.assignee_id, title, due_at, status, related_to, tenant_id
_eventsTransactional outbox.type, doc_id, payload, created_at
Keep search_text denormalized. A NonoDB text index covers one field. Build a 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.

MongoDB drivers cannot use vault headers. The wire endpoint is for standard collections inside the documented subset. Use the native client or HTTP API for vault access.

Where another tool fits better

Ship the CRM, not the infrastructure.

Run the CRM on one database.