mongoose vs bookshelf vs sequelize vs waterline
Selecting a Data Modeling Library for Node.js Services
mongoosebookshelfsequelizewaterlineSimilar Packages:

Selecting a Data Modeling Library for Node.js Services

bookshelf, mongoose, sequelize, and waterline are libraries that help Node.js applications interact with databases by organizing data into models. mongoose is designed for MongoDB and uses a document-based approach, while sequelize, bookshelf, and waterline support relational SQL databases like PostgreSQL and MySQL. These tools handle connections, define data shapes, and simplify queries so developers do not need to write raw SQL or database commands for every action. Choosing the right one depends on your database type, project size, and long-term maintenance needs.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
mongoose4,978,28027,4722.07 MB18314 days agoMIT
bookshelf06,362-2386 years agoMIT
sequelize030,3522.91 MB1,023a month agoMIT
waterline05,3981.3 MB34-MIT

Bookshelf vs Mongoose vs Sequelize vs Waterline: Data Modeling Compared

When building Node.js backends β€” whether for API servers, serverless functions, or full-stack frameworks β€” you need a reliable way to talk to your database. bookshelf, mongoose, sequelize, and waterline all solve this problem, but they target different databases and work in different ways. Let's compare how they handle common engineering tasks.

πŸ—„οΈ Database Support: SQL vs NoSQL

The first decision is your database type. This choice often dictates which library you can use.

mongoose works only with MongoDB.

  • It treats data as JSON-like documents.
  • Great for flexible schemas and hierarchical data.
// mongoose: MongoDB only
const mongoose = require('mongoose');
// Connects to MongoDB instance
mongoose.connect('mongodb://localhost:27017/myapp');

sequelize works with SQL databases.

  • Supports PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server.
  • Enforces strict table structures and relationships.
// sequelize: SQL databases
const { Sequelize } = require('sequelize');
// Connects to SQL instance
const sequelize = new Sequelize('postgres://user:pass@localhost:5432/db');

bookshelf works with SQL databases via Knex.js.

  • Supports the same SQL dialects as Knex (Postgres, MySQL, etc.).
  • Focuses on mapping rows to models.
// bookshelf: SQL databases via Knex
const knex = require('knex')({ client: 'pg' });
const bookshelf = require('bookshelf')(knex);
// Uses Knex connection for SQL

waterline works with both SQL and NoSQL via adapters.

  • Can switch between Mongo, Postgres, MySQL, etc., by changing config.
  • Historically tied to Sails.js but works standalone.
// waterline: Adapter-based
const Waterline = require('waterline');
const waterline = new Waterline();
// Adapters determine DB type (mongo, postgres, etc.)

πŸ“ Defining Data Shapes: Schemas and Models

Each library has a different way to define what your data looks like.

mongoose uses Schemas to define document structure.

  • You define types and validation rules upfront.
  • Flexible but enforces consistency.
// mongoose: Schema definition
const userSchema = new mongoose.Schema({
  name: String,
  email: { type: String, unique: true }
});
const User = mongoose.model('User', userSchema);

sequelize uses Model Definitions with data types.

  • You define columns and types explicitly.
  • Supports strong typing and validation.
// sequelize: Model definition
const User = sequelize.define('User', {
  name: { type: Sequelize.STRING },
  email: { type: Sequelize.STRING, unique: true }
});

bookshelf extends a Base Model with table names.

  • Less focus on types, more on mapping rows.
  • Relies on Knex for schema management.
// bookshelf: Model extension
const User = bookshelf.Model.extend({
  tableName: 'users',
  // Validation handled externally or via plugins
});

waterline uses Collection Definitions.

  • Defines attributes and types similar to ORM models.
  • Adapter handles the underlying storage details.
// waterline: Collection definition
const User = waterline.Collection.extend({
  tableName: 'users',
  attributes: {
    name: { type: 'string' },
    email: { type: 'string', unique: true }
  }
});

πŸ” Fetching Data: Querying Patterns

How you retrieve data varies significantly between these tools.

mongoose uses Chainable Queries on models.

  • Methods like find, findOne, findById are standard.
  • Returns plain JavaScript objects or documents.
// mongoose: Finding documents
const users = await User.find({ role: 'admin' });
const user = await User.findOne({ email: 'test@example.com' });

sequelize uses Finder Methods with options objects.

  • findAll, findOne, findByPk are common.
  • Supports complex includes for relationships.
// sequelize: Finding rows
const users = await User.findAll({ where: { role: 'admin' } });
const user = await User.findOne({ where: { email: 'test@example.com' } });

bookshelf uses Knex-style Querying on models.

  • Uses where, fetch, fetchAll methods.
  • Closely mirrors SQL logic.
// bookshelf: Fetching models
const users = await User.where({ role: 'admin' }).fetchAll();
const user = await User.where({ email: 'test@example.com' }).fetch();

waterline uses Criteria Objects for queries.

  • find, findOne accept simple objects.
  • Abstracts away SQL vs NoSQL query differences.
// waterline: Finding records
const users = await User.find({ role: 'admin' });
const user = await User.findOne({ email: 'test@example.com' });

πŸ› οΈ Maintenance and Ecosystem Health

For professional developers, long-term support is critical. You do not want to build on a library that stops receiving updates.

mongoose is highly active.

  • Regular releases and security patches.
  • Massive ecosystem of plugins and tutorials.
  • Safe choice for new MongoDB projects.

sequelize is highly active.

  • Consistent updates for SQL features and security.
  • Strong TypeScript support and community.
  • Safe choice for new SQL projects.

bookshelf has low activity.

  • Development has slowed significantly in recent years.
  • Still works, but new features are rare.
  • Consider for legacy maintenance, not new builds.

waterline has low activity standalone.

  • Primarily maintained for Sails.js framework users.
  • Standalone usage is less common and harder to support.
  • Evaluate carefully if not using Sails.

πŸ“Š Summary: Key Differences

Featuremongoosesequelizebookshelfwaterline
DatabaseπŸƒ MongoDB onlyπŸ—„οΈ SQL (Postgres, MySQL)πŸ—„οΈ SQL (via Knex)πŸ”„ Both (via adapters)
StyleπŸ“„ Document ODMπŸ—ƒοΈ Relational ORMπŸ—ƒοΈ Relational ORMπŸ”„ Datastore Agnostic
Activity🟒 High🟒 High🟑 Low🟑 Low
Best ForπŸš€ New Mongo Apps🏒 Enterprise SQLπŸ•°οΈ Legacy Knex Appsβ›΅ Sails.js Apps

πŸ’‘ The Big Picture

mongoose and sequelize are the industry standards for new projects. Choose mongoose for MongoDB and sequelize for SQL databases. They have the best documentation, community support, and active maintenance.

bookshelf and waterline are older tools with specific use cases. bookshelf fits if you love Knex and need a light model layer. waterline fits if you are already using Sails.js. For most other scenarios, the active maintenance of mongoose and sequelize makes them the safer choice for long-term stability.

Final Thought: Your database choice should drive your library choice. Pick your database first based on data needs, then pick the library that supports it best with active community backing.

How to Choose: mongoose vs bookshelf vs sequelize vs waterline

  • mongoose:

    Choose mongoose if your application uses MongoDB and you need a robust schema system with built-in validation. It is the standard choice for Node.js and MongoDB, offering strong community support and extensive plugins. This is ideal for content-heavy apps, real-time data, or when your data structure changes frequently.

  • bookshelf:

    Choose bookshelf if you are already using Knex.js and want a thin model layer on top of it for SQL databases. It is suitable for legacy projects or teams that prefer explicit control over SQL queries without heavy abstraction. However, be aware that development activity has slowed, so it may not be the best fit for new greenfield projects requiring long-term support.

  • sequelize:

    Choose sequelize if you are working with relational databases like PostgreSQL, MySQL, or SQLite and want a feature-rich ORM. It supports migrations, associations, and transactions out of the box, making it great for complex business logic. It is widely maintained and a safe bet for enterprise-grade SQL applications.

  • waterline:

    Choose waterline primarily if you are building an application with the Sails.js framework, as it is tightly integrated into that ecosystem. It supports both SQL and NoSQL databases through adapters, offering flexibility if you need to switch database types later. For standalone Node.js projects outside of Sails, other options may offer better documentation and community support.

README for mongoose

Mongoose

Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha).

Build Status NPM version Deno version Deno popularity

npm

Documentation

The official documentation website is mongoosejs.com.

Mongoose 9.0.0 was released on November 21, 2025. You can find more details on backwards breaking changes in 9.0.0 on our docs site.

Support

Plugins

Check out the plugins search site to see hundreds of related modules from the community. Next, learn how to write your own plugin from the docs or this blog post.

Contributors

Pull requests are always welcome! Please base pull requests against the master branch and follow the contributing guide.

If your pull requests makes documentation changes, please do not modify any .html files. The .html files are compiled code, so please make your changes in docs/*.pug, lib/*.js, or test/docs/*.js.

View all 400+ contributors.

Installation

First install Node.js and MongoDB, then install the mongoose package using your preferred package manager:

Using npm

npm install mongoose

Using pnpm

pnpm add mongoose

Using Yarn

yarn add mongoose

Using Bun

bun add mongoose

Mongoose 6.8.0 also includes alpha support for Deno.

Importing

// Using Node.js `require()`
const mongoose = require('mongoose');

// Using ES6 imports
import mongoose from 'mongoose';

Or, using Deno's createRequire() for CommonJS support as follows.

import { createRequire } from 'https://deno.land/std@0.177.0/node/module.ts';
const require = createRequire(import.meta.url);

const mongoose = require('mongoose');

mongoose.connect('mongodb://127.0.0.1:27017/test')
  .then(() => console.log('Connected!'));

You can then run the above script using the following.

deno run --allow-net --allow-read --allow-sys --allow-env mongoose-test.js

Mongoose for Enterprise

Available as part of the Tidelift Subscription

The maintainers of mongoose and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Overview

Connecting to MongoDB

First, we need to define a connection. If your app uses only one database, you should use mongoose.connect. If you need to create additional connections, use mongoose.createConnection.

Both connect and createConnection take a mongodb:// URI, or the parameters host, database, port, options.

await mongoose.connect('mongodb://127.0.0.1/my_database');

Once connected, the open event is fired on the Connection instance. If you're using mongoose.connect, the Connection is mongoose.connection. Otherwise, mongoose.createConnection return value is a Connection.

Note: If the local connection fails then try using 127.0.0.1 instead of localhost. Sometimes issues may arise when the local hostname has been changed.

Important! Mongoose buffers all the commands until it's connected to the database. This means that you don't have to wait until it connects to MongoDB in order to define models, run queries, etc.

Defining a Model

Models are defined through the Schema interface.

const Schema = mongoose.Schema;
const ObjectId = Schema.ObjectId;

const BlogPost = new Schema({
  author: ObjectId,
  title: String,
  body: String,
  date: Date
});

Aside from defining the structure of your documents and the types of data you're storing, a Schema handles the definition of:

The following example shows some of these features:

const Comment = new Schema({
  name: { type: String, default: 'hahaha' },
  age: { type: Number, min: 18, index: true },
  bio: { type: String, match: /[a-z]/ },
  date: { type: Date, default: Date.now },
  buff: Buffer
});

// a setter
Comment.path('name').set(function(v) {
  return capitalize(v);
});

// middleware
Comment.pre('save', function(next) {
  notify(this.get('email'));
  next();
});

Take a look at the example in examples/schema/schema.js for an end-to-end example of a typical setup.

Accessing a Model

Once we define a model through mongoose.model('ModelName', mySchema), we can access it through the same function

const MyModel = mongoose.model('ModelName');

Or just do it all at once

const MyModel = mongoose.model('ModelName', mySchema);

The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural version of your model name. For example, if you use

const MyModel = mongoose.model('Ticket', mySchema);

Then MyModel will use the tickets collection, not the ticket collection. For more details read the model docs.

Once we have our model, we can then instantiate it, and save it:

const instance = new MyModel();
instance.my.key = 'hello';
await instance.save();

Or we can find documents from the same collection

await MyModel.find({});

You can also findOne, findById, update, etc.

const instance = await MyModel.findOne({ /* ... */ });
console.log(instance.my.key); // 'hello'

For more details check out the docs.

Important! If you opened a separate connection using mongoose.createConnection() but attempt to access the model through mongoose.model('ModelName') it will not work as expected since it is not hooked up to an active db connection. In this case access your model through the connection you created:

const conn = mongoose.createConnection('your connection string');
const MyModel = conn.model('ModelName', schema);
const m = new MyModel();
await m.save(); // works

vs

const conn = mongoose.createConnection('your connection string');
const MyModel = mongoose.model('ModelName', schema);
const m = new MyModel();
await m.save(); // does not work b/c the default connection object was never connected

Embedded Documents

In the first example snippet, we defined a key in the Schema that looks like:

comments: [Comment]

Where Comment is a Schema we created. This means that creating embedded documents is as simple as:

// retrieve my model
const BlogPost = mongoose.model('BlogPost');

// create a blog post
const post = new BlogPost();

// create a comment
post.comments.push({ title: 'My comment' });

await post.save();

The same goes for removing them:

const post = await BlogPost.findById(myId);
post.comments[0].deleteOne();
await post.save();

Embedded documents enjoy all the same features as your models. Defaults, validators, middleware.

Middleware

See the docs page.

Intercepting and mutating method arguments

You can intercept method arguments via middleware.

For example, this would allow you to broadcast changes about your Documents every time someone sets a path in your Document to a new value:

schema.pre('set', function(next, path, val, typel) {
  // `this` is the current Document
  this.emit('set', path, val);

  // Pass control to the next pre
  next();
});

Moreover, you can mutate the incoming method arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to next:

schema.pre(method, function firstPre(next, methodArg1, methodArg2) {
  // Mutate methodArg1
  next('altered-' + methodArg1.toString(), methodArg2);
});

// pre declaration is chainable
schema.pre(method, function secondPre(next, methodArg1, methodArg2) {
  console.log(methodArg1);
  // => 'altered-originalValOfMethodArg1'

  console.log(methodArg2);
  // => 'originalValOfMethodArg2'

  // Passing no arguments to `next` automatically passes along the current argument values
  // i.e., the following `next()` is equivalent to `next(methodArg1, methodArg2)`
  // and also equivalent to, with the example method arg
  // values, `next('altered-originalValOfMethodArg1', 'originalValOfMethodArg2')`
  next();
});

Schema gotcha

type, when used in a schema has special meaning within Mongoose. If your schema requires using type as a nested property you must use object notation:

new Schema({
  broken: { type: Boolean },
  asset: {
    name: String,
    type: String // uh oh, it broke. asset will be interpreted as String
  }
});

new Schema({
  works: { type: Boolean },
  asset: {
    name: String,
    type: { type: String } // works. asset is an object with a type property
  }
});

Driver Access

Mongoose is built on top of the official MongoDB Node.js driver. Each mongoose model keeps a reference to a native MongoDB driver collection. The collection object can be accessed using YourModel.collection. However, using the collection object directly bypasses all mongoose features, including hooks, validation, etc. The one notable exception that YourModel.collection still buffers commands. As such, YourModel.collection.find() will not return a cursor.

API Docs

Mongoose API documentation, generated using dox and acquit.

Related Projects

MongoDB Runners

Unofficial CLIs

Data Seeding

Express Session Stores

License

Copyright (c) 2010 LearnBoost <dev@learnboost.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.