# mongocache

> Superfast cached/indexed queries from MongoDB!

Latest version **0.1.2** (published 2015-07-13) · ISC license · 0 weekly downloads

## Install

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

## 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 | 2015-07-13 |
| First published | 2014-12-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Juha Lindstedt |
| Maintainers | pakastin |

## Links

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

## Dependencies (2)

- [mongodb](https://npm.io/package/mongodb.md) ^2.0.36
- [highland](https://npm.io/package/highland.md) ^2.5.1

## Recent versions

- 0.1.2 (latest) — 2015-07-13
- 0.1.1 — 2015-07-10
- 0.1.0 — 2015-07-10
- 0.0.8 — 2015-05-11
- 0.0.7 — 2015-04-30
- 0.0.6 — 2015-04-16
- 0.0.5 — 2015-02-04
- 0.0.4 — 2014-12-04
- 0.0.2 — 2014-12-02

## README

# mongocache

Gets ALL documents (only selected keys) from MongoDB and keeps them updated with [oplog](https://blog.compose.io/the-mongodb-oplog-and-node-js/).
Also indexes collections, providing instantenous queries. Uses native MongoDB client, so it's superfast.

Especially useful if need to maintain and query complex tree hierarchies.

## installation

```javascript
npm install mongocache --save
```

## usage

```javascript
var mongocache = require('mongocache')
var dbcache = mongocache({
  dbname: {
    levels: {
      select: '_id parent name', // only keep these keys
      index: 'parent' // index 'parent' -value
    }
  }
})

setInterval(function () {
  // get all docs
  dbcache.dbname.levels.getAll(function (docs) {
      console.log(docs)
  })
  // find by _id
  dbcache.dbname.levels.findById('507f1f77bcf86cd799439011', function (doc) {
      console.log(doc)
  })
  // find by indexed key ('parent' === '507f1f77bcf86cd799439011')
  dbcache.dbname.levels.find('parent', '507f1f77bcf86cd799439011', function (docs) {
      console.log(docs)
  })
  // find first by indexed key ('parent' === '507f1f77bcf86cd799439011')
  dbcache.dbname.levels.findOne('parent', '507f1f77bcf86cd799439011', function (doc) {
      console.log(doc)
  })
}, 1000)
```

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