# fh-rest-mongodb-adapter

> MongoDB adapter for fh-rest-express-router

Latest version **0.2.0** (published 2016-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install fh-rest-mongodb-adapter
pnpm add fh-rest-mongodb-adapter
yarn add fh-rest-mongodb-adapter
bun add fh-rest-mongodb-adapter
```

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2016-07-26 |
| First published | 2016-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Evan Shortiss |
| Maintainers | evanshortiss |

## Links

- npm: https://www.npmjs.com/package/fh-rest-mongodb-adapter
- npm.io page: https://npm.io/package/fh-rest-mongodb-adapter

## Dependencies (9)

- [joi](https://npm.io/package/joi.md) ^9.0.1
- [async](https://npm.io/package/async.md) ^2.0.0
- [verror](https://npm.io/package/verror.md) ^1.6.1
- [env-var](https://npm.io/package/env-var.md) ^1.0.0
- [linelint](https://npm.io/package/linelint.md) ^1.0.1
- [fh-bunyan](https://npm.io/package/fh-bunyan.md) ^0.1.3
- [is-object](https://npm.io/package/is-object.md) ^1.0.1
- [lodash.map](https://npm.io/package/lodash.map.md) ^4.4.0
- [mongo-utils](https://npm.io/package/mongo-utils.md) git+https://github.com/evanshortiss/mongo-utils.git#0.2.0

## Recent versions

- 0.2.0 (latest) — 2016-07-26

## README

fh-rest-mongodb-adapter
=======================

A MongoDB adapater compatible with the _fh-rest-express-router_. Allows one to
easily create a RESTful API that uses MongoDB as a datastore.

## Example

The code below will generate routes that can be used [like this](https://github.com/feedhenry-staff/fh-rest-express-router#restful-api-definition)

```js
'use strict';

var app = require('express')()
  , fhRestRouter = require('fh-rest-express-router')
  , fhRestMongoAdapter = require('fh-rest-mongodb-adapter');

app.use(
  '/tasks',
  fhRestMongoAdapter({
    // Collection to expose
    collection: 'user-tasks',

    // Optional mongo connection string. When on RHMAP this is filled for you
    mongoUrl: 'mongodb://host-name.com/27017/database-name',

    // Indexes you'd like to apply to collections in use
    indexes: [{
      userId: 1
    }]
  })
);

app.listen(3001);
```

## Direct API
Works just like the [memory adapter](https://github.com/feedhenry-staff/fh-rest-memory-adapter#direct-api),
with the exception being _params.query_ passed to _adapter.list_ can contain
Mongo specific operators, e.g $gte. For example:

```js
var payloads = fhRestMongoAdapter({
  // Collection to expose
  collection: 'payloads'
});

payloads.list({
  query: {
    createDate: {
      $lte: new Date()
    }
  }
}, function (err, payloads) {});
```

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