https://github.com/firstandthird/hapi-mongodb-collections
https://github.com/firstandthird/hapi-mongodb-collections
hapi-plugin
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/firstandthird/hapi-mongodb-collections
- Owner: firstandthird
- License: mit
- Created: 2016-10-14T10:28:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T22:30:32.000Z (almost 5 years ago)
- Last Synced: 2025-05-30T10:16:17.671Z (9 months ago)
- Topics: hapi-plugin
- Language: JavaScript
- Size: 13.7 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## hapi-mongodb-collections
A [hapi](https://hapi.dev/) helper that makes it easier to access your mongodb collections.
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__ (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" })
```