These examples are intentionally simple and focused on Coral's core routing features. Each file is self-contained and ready to run after installing dependencies.
- Node.js 20+
- MongoDB running locally, or set
MONGO_URI
npm install express mongoose coralnode examples/basic-crud.js- Baseline CRUD resource using schema validation and indexes.
- Covers:
path,model,perPage,bodyFilter.
- Restrict methods and run middleware before Coral handlers.
- Covers:
methods,middlewares,fields,bodyFilter.
- Route by business key from URL params instead of
_id. - Covers:
idAttribute,idParam,methods,middlewares.
- Apply default filters/options/projections with safe runtime overrides.
- Covers:
conditions,options,fields,query,perPage.
- Demonstrates page-based pagination and limit capping behavior.
- Covers:
perPage, query runtime behavior.
- Whitelist request body keys to prevent mass assignment.
- Covers:
bodyFilter,methods.
- Update parent references during create operations.
- Covers:
updateRef.
- CRUD operations for embedded arrays under a parent document.
- Covers:
subDoc, top-levelidAttribute, top-levelidParam.
- Nested
subDocconfiguration for multi-level embedded routing. - Covers: recursive
subDoc.subDoc, mixedidParam+idAttribute.
For list routes (GET <path>):
skiplimitpagesortorder(asc,desc,1,-1)select(comma-separated list)
MONGO_URI(optional, defaults to local MongoDB)INTERNAL_API_KEY(used bymethods-and-middlewares.js)