Skip to content

firstandthird/hapi-mongodb-collections

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapi-mongodb-collections

A hapi helper that makes it easier to access your mongodb collections.

No more

server.plugins['hapi-mongodb'].db.collection('myCollection').find({});

instead you just do:

server.myCollection.find({});

Installation

npm install hapi-mongodb-collections

Use

First make sure you have registered 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

const plugin = require('hapi-mongodb-collections');
await server.register({
  plugin,
  options: {
    collections: [
      'myCoinCollection',
      'myShellCollection',
      'myStampCollection'
    ]
  }
});

will make it possible to do:

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:

    {
      collections: [
        'myCoinCollection'
      ],
      namespace: 'collections'
    }

    in your plugin options will let you make queries like so:

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

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •