Guides  ›  Database  ›  Create ← PREV NEXT →

Create

Use this in a POST route with a schema requiring name and email.

async function handler(state) {
  var data = state.take(['name', 'email'], state.req.body.params)
  var result = await state.plugins.mongodb
    .collection('users').insertOne(data)

  return state.jarpc({ ok: true, data: { id: result.insertedId } })
}

The document ID belongs in data; the response ID identifies the request.

Next: Update →

Tools for business systems.