# mongomock

> [![NPM](https://nodei.co/npm/mongomock.png?downloads=true)](https://nodei.co/npm/mongomock/)

Latest version **0.1.2** (published 2014-08-19) · 0 weekly downloads

## Install

```sh
npm install mongomock
pnpm add mongomock
yarn add mongomock
bun add mongomock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-08-19 |
| First published | 2014-04-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | andrewgrachov |

## Links

- npm: https://www.npmjs.com/package/mongomock
- Repository: https://github.com/AndrewGrachov/mongomock
- Issues: https://github.com/AndrewGrachov/mongomock/issues
- npm.io page: https://npm.io/package/mongomock

## Dependencies (1)

- [bson](https://npm.io/package/bson.md) *

## Recent versions

- 0.1.2 (latest) — 2014-08-19
- 0.1.1 — 2014-08-13
- 0.1.0 — 2014-08-13
- 0.0.8 — 2014-06-03
- 0.0.7 — 2014-06-03
- 0.0.6 — 2014-04-18
- 0.0.5 — 2014-04-17
- 0.0.4 — 2014-04-16
- 0.0.3 — 2014-04-09
- 0.0.2 — 2014-04-05
- 0.0.1 — 2014-04-05

## README

[![NPM](https://nodei.co/npm/mongomock.png?downloads=true)](https://nodei.co/npm/mongomock/)

mongomock
=========

mongoDb-native mocking library

Also the query engine works for basic js collections as well

Standalone version for a browser usage is [here](https://github.com/AndrewGrachov/mongo-query)

You can try a playground [here](http://andrewgrachov.github.io/mongo-query/)

#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

---
_Source: https://npm.io/package/mongomock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
