-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from firstandthird/readme
Update readme.md
- Loading branch information
Showing
1 changed file
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) | ||
``` |