mongomock

0.1.2 • Public • Published

NPM

mongomock

mongoDb-native mocking library

Also the query engine works for basic js collections as well

Standalone version for a browser usage is here

You can try a playground here

Dependencies

bson

Install

npm install mongomock

Getting started

var MongoMock = require('mongomock');

//initial mock data
var db = {
    fruits:[{name:'Banana',price:20},{name:'Apple',price:10,tags:['Africa','Turkey']},
    {name:'Orange',price:25},{name:'Pineapple',price:20}],
    beverages:[{name:'CocaCola',price:15},{name:'MongoCola',price:10},{name:'Pepsi',price:25}]
}

var mongo = new MongoMock(db);

mongo.collection('fruits').find({price:20}).toArray(function(err,fruits){
  console.log("YAHOO we have fruits with price 20 now!",fruits);
})

Update 0.1.0 basic cursor implementation without skip/limit chaining

Testing

Tests use mocha. Install mocha globally, then run

npm test

Methods support

collection.find(query, fields, options) - returns readable stream

collection.findOne(query, callback)

collection.update(query,modifier,options,callback)

collection.insert(doc,callback)

collection.remove(query,callback)

collection.findAndModify(doc,modifier,options,callback)

collection.save(doc,callback)

Query operators support:

$gte

$gt

$lt

$lte

$in

$regex

$and

$or

$ne

$nin

$size

$elemMatch

$exists

$all

Modifier operators support

$set

$unset

$inc

$addToSet

$rename

$pull

$push

$each

On the way

  1. Date(and types) support
  2. projections support

Readme

Keywords

none

Package Sidebar

Install

npm i mongomock

Weekly Downloads

281

Version

0.1.2

License

none

Last publish

Collaborators

  • andrewgrachov