Mock your mongoose entities !

npm install monckoose
22 downloads in the last week
29 downloads in the last month

Build Status

What's monckoose?

Monckoose helps you working with mongoose but without any database. It provides a fake driver and a collection helper to make it easy to code any entity mocks. No database needed, no connection needed, just a js file with your entities.


$ npm install monckoose


First you need to put this line before any require of 'mongoose' :


Because it sets a global variable to tell mongoose to use the monckoose driver instead of the native one.

Then add the mocks location to options :

mongoose.connect('mongodb://localhost/mocks', { mocks: require(path.join(__dirname, 'myMocks')) });

Create a mocks module in myMocks.js, for example :

var monckoose = require('monckoose')
  , mocks, contacts;

contacts = [
  { name: 'Robert', company: 'fake', email: '', _id: '51605fe1779ade6334000009', __v: 0 },
  { name: 'Jennifer', company: 'fake', email: '', _id: '51605fe1779ade6334000004', __v: 0 }

mocks = {
  contacts: new monckoose.MonckooseCollection(contacts)

module.exports = exports = mocks;

That's all! Now you can work as usual with mongoose, for example :

var Contact = mongoose.model('Contact', {
  name: String,
  company: String,
  email: String
var john = new Contact({ name: 'John', company: 'woo', email: '' }); (err) {


Currently available methods are limited to : find, findOne, insert, remove, save, update, findAndModify. Contributions are welcome to complete MonckooseCollection prototype.

See unit tests in spec for more examples

Enjoy !

npm loves you