Skip to content

Commit

Permalink
Merge pull request #5 from firstandthird/readme
Browse files Browse the repository at this point in the history
Update readme.md
  • Loading branch information
orthagonal committed Feb 25, 2021
2 parents 5172927 + 76213cd commit 62bb309
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
## hapi-mongodb-collections

Decorates server object with collections.
A [hapi](https://hapi.dev/) helper that makes it easier to access your mongodb collections.

Include this plugin after `hapi-mongodb`.
No more
```javascript
server.plugins['hapi-mongodb'].db.collection('myCollection').find({});
```

instead you just do:

```javascript
server.myCollection.find({});
```

## Installation

```console
npm install hapi-mongodb-collections
```

## Use

First make sure you have registered [hapi-mongodb](https://github.com/Marsup/hapi-mongodb)
with the server. Then register hapi-mongodb-collections and specify the collections you want to make available directory from your server object.

## Example

```javascript
const plugin = require('hapi-mongodb-collections');
await server.register({
plugin,
options: {
collections: [
'myCoinCollection',
'myShellCollection',
'myStampCollection'
]
}
});
```
will make it possible to do:

```javascript
await server.myCoinCollection.find({ type: 'dimes' });
```

## Options

Options:
- `collections` - Array of collection names.
- __collections__ (required)
An array of collection names.
- __namespace__
If you want to put your collections under a namespace, you can. So for example passing:
```javascript
{
collections: [
'myCoinCollection'
],
namespace: 'collections'
}
```
in your plugin options will let you make queries like so:

```javascript
server.collections.myCoinCollection.find({ type: "dimes" })
```

0 comments on commit 62bb309

Please sign in to comment.