Tutorial: a small shop
In ten short steps you build a Nuxt app with customers and orders, and use every feature of declared collections on the way:
| Step | You add | Feature |
|---|---|---|
| 1. Setup | the module and the embedded server | MongoDB over REST in your Nuxt app |
| 2. First collection | customers with a schema | typed documents on client and server |
| 3. Validation | validation: 'error', a form with errors | schema validation, issues, the MongoDB validator |
| 4. Behaviours | orders with timestamps, owner, soft delete, versions, audit | per-collection rules without writing routes |
| 5. Hooks | a Nitro plugin that computes the total | before-hooks, protected fields |
| 6. Indexes | unique email, list indexes | indexes in the declaration |
| 7. Relations | customerId refers to a customer | refs and expand |
| 8. Live updates | the order list updates itself | useMongocampLive |
| 9. Server code | a route that places orders | useMongocampServerCollection |
| 10. Going to production | server rendering, limits | what to set before going live |
The finished app is in the repository at docs/tutorial/app. Every code block of these pages is taken from its files, and a test runs the app and checks what each step says. So the code here is the code that works.
Before you start
- Node 22.22 or newer and a Nuxt 4.7 app (
pnpm create nuxt@latest shop) - a MongoDB on
localhost:27017, for exampledocker run -d -p 27017:27017 mongo:7 - for step 8 a replica set; without one the list falls back to polling, and nothing in your code changes
If you know Mongoose, Coming from Mongoose maps its concepts to the ones used here.
