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({});
npm install hapi-mongodb-collections
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.
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:
-
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" })