A mongodb service for feathers
Latest commit 6aec967 Jan 19, 2017 @daffl daffl Updating changelog



Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

A MongoDB CRUD service for FeathersJS


npm install mongodb feathers-mongodb --save


Please refer to the Feathers database adapter documentation for more details or directly at:

  • MongoDB - The detailed documentation for this adapter
  • Extending - How to extend a database adapter
  • Pagination and Sorting - How to use pagination and sorting for the database adapter
  • Querying - The common adapter querying mechanism

Getting Started

You can create a MongoDB service like this:

var MongoClient = require('mongodb').MongoClient;
var service = require('feathers-mongodb');
var app = feathers();

  app.use('/messages', service({
    Model: db


This will create a messages endpoint and connect to a local messages collection on the feathers database.

Complete Example

Here's a complete example of a Feathers server with a messages MongoDB service.

const feathers = require('feathers');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const handler = require('feathers-errors/handler');
const bodyParser = require('body-parser');
var MongoClient = require('mongodb').MongoClient;
const service = require('feathers-mongodb');

// Create a feathers instance.
const app = feathers()
  // Enable Socket.io
  // Enable REST services
  // Turn on JSON parser for REST services
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({extended: true}));

const promise = new Promise(function(resolve) {
  // Connect to your MongoDB instance(s)
    // Connect to the db, create and register a Feathers service.
    app.use('/messages', service({
      Model: db.collection('messages'),
      paginate: {
        default: 2,
        max: 4

    // A basic error handler, just like Express

    // Start the server
    var server = app.listen(3030);
    server.on('listening', function() {
      console.log('Feathers Message MongoDB service running on');

module.exports = promise;

You can run this example by using npm start and going to localhost:3030/messages. You should see an empty array. That's because you don't have any messages yet but you now have full CRUD for your new message service!


Copyright (c) 2016

Licensed under the MIT license.