Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thebergamo/k7-mongoose
K7 adapter for Mongoose ODM :squirrel:
https://github.com/thebergamo/k7-mongoose
hapi hapi-plugin k7 mongoose
Last synced: 3 months ago
JSON representation
K7 adapter for Mongoose ODM :squirrel:
- Host: GitHub
- URL: https://github.com/thebergamo/k7-mongoose
- Owner: thebergamo
- License: isc
- Created: 2016-02-29T17:45:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T19:33:50.000Z (almost 8 years ago)
- Last Synced: 2024-09-16T02:14:30.460Z (3 months ago)
- Topics: hapi, hapi-plugin, k7, mongoose
- Language: JavaScript
- Size: 21.5 KB
- Stars: 3
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
k7-mongoose
===
`k7` adapter for mongoose ODM[![Build Status](https://travis-ci.org/thebergamo/k7-mongoose.svg)](https://travis-ci.org/thebergamo/k7-mongoose)
Lead Maintainer: [Marcos Bérgamo](https://github.com/thebergamo)
## Example Usage
```javascript
const Hapi = require('hapi');
const Server = new Hapi.Server();Server.connection({host: 'localhost'});
let options = {
adapter: require('k7-mongoose'),
connectionString: 'mongodb://localhost:27017/K7Mongoose',
promise: global.Promise
};Server.register({
register: require('k7'),
options: options
}, (err) => {
if (err) {
throw err;
}
Server.start((err) => {
if (err) {
throw err;
}
Server.log('info', 'Server running at: ' + Server.info.uri);
});
});
```This example does the following:
1. Setting the k7-mongoose adapter
2. Setting the connectionString for mongoose connect
3. Register the k7 to Hapi.js## Options
All the options available in [Mongoose][mongoose] can be setted in `connectionOptions`.## Set up the models
You can define your models schema like you're already do, but you need to replace the `const mongoose = require('mongoose');` on top of your models by update with `const mongoose = require('k7-mongoose').mongoose();`**Why this is required?** Because mongoose is a singleton, therefore you need to use the **k7-mongoose** instantiated version.
[mongoose]: http://mongoosejs.com/