Skip to content

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:

StepYou addFeature
1. Setupthe module and the embedded serverMongoDB over REST in your Nuxt app
2. First collectioncustomers with a schematyped documents on client and server
3. Validationvalidation: 'error', a form with errorsschema validation, issues, the MongoDB validator
4. Behavioursorders with timestamps, owner, soft delete, versions, auditper-collection rules without writing routes
5. Hooksa Nitro plugin that computes the totalbefore-hooks, protected fields
6. Indexesunique email, list indexesindexes in the declaration
7. RelationscustomerId refers to a customerrefs and expand
8. Live updatesthe order list updates itselfuseMongocampLive
9. Server codea route that places ordersuseMongocampServerCollection
10. Going to productionserver rendering, limitswhat 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 example docker 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.

Released under the MIT License.