Ottoman is an ODM for Couchbase. Use it when your application stores JSON documents in Couchbase buckets, scopes, and collections and you want model definitions, validation, query helpers, and indexes around that document layer.
Ottoman setup
01Installpnpm add ottoman couchbase
02Schema & modelnew Schema · model('User')
03Pluginconnect · start · decorate('db')
04Augment stateinterface AppState { db }
05Use in routesstate.db.User.findById()
Ottoman connects once and runs ottoman.start() to build indexes before traffic arrives. Handlers then read the decorated state.db model surface.
1. Install
ts
pnpm add ottoman couchbase
2. Define a schema and model
ts
// src/db/ottoman.tsimport { Ottoman, Schema, model } from "ottoman";export const ottoman = new Ottoman({ collectionName: "users",});const userSchema = new Schema({ email: { type: String, required: true }, name: { type: String, required: false },});userSchema.index.findByEmail = { by: "email", type: "n1ql",};export const User = model("User", userSchema);export const db = { ottoman, User };
3. Create an Ottoman plugin
Connect once during app startup, build indexes with ottoman.start(), decorate the app with the models you want handlers to use, and close the connection on shutdown.
Define indexes next to the schema and run ottoman.start() during startup so query helpers are ready before the server accepts traffic. Keep index creation out of request handlers.
Ottoman is best for model-centric Couchbase document access. If a workflow requires Couchbase distributed transactions, expose the Couchbase SDK objects you need through the same plugin and keep that transaction boundary inside the handler that owns the unit of work.
Runtime constraints
Ottoman depends on the Couchbase Node.js SDK, so it is a Node.js-first ODM. It is not a fit for Cloudflare Workers or Vercel. For edge-compatible data access, use the SQL ORM overview and choose a compatible client.