{"id":26331467,"url":"https://github.com/iniva/hapi-nosql-mongoose","last_synced_at":"2026-05-08T11:33:16.325Z","repository":{"id":54267485,"uuid":"132235665","full_name":"iniva/hapi-nosql-mongoose","owner":"iniva","description":"Mongoose plugin for HapiJS (v17+)","archived":false,"fork":false,"pushed_at":"2021-02-28T09:51:54.000Z","size":257,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T09:03:03.745Z","etag":null,"topics":["hapi-plugin","hapijs","mongodb","mongoose"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iniva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-05T09:58:34.000Z","updated_at":"2021-02-28T09:51:28.000Z","dependencies_parsed_at":"2022-08-13T10:30:57.788Z","dependency_job_id":null,"html_url":"https://github.com/iniva/hapi-nosql-mongoose","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iniva%2Fhapi-nosql-mongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iniva%2Fhapi-nosql-mongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iniva%2Fhapi-nosql-mongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iniva%2Fhapi-nosql-mongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iniva","download_url":"https://codeload.github.com/iniva/hapi-nosql-mongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801598,"owners_count":20350106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hapi-plugin","hapijs","mongodb","mongoose"],"created_at":"2025-03-15T22:37:27.206Z","updated_at":"2026-05-08T11:33:11.299Z","avatar_url":"https://github.com/iniva.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e :warning: This won't be updated anymore\n\n# hapi-nosql-mongoose\nMongoose plugin for [HapiJS](https://hapijs.com/) (v17+)\n\n- [hapi-nosql-mongoose](#hapi-nosql-mongoose)\n  - [Installation](#installation)\n  - [Register as Hapi Plugin](#register-as-hapi-plugin)\n      - [Options](#options)\n      - [Schema Definitions](#schema-definitions)\n  - [Server Decorations](#server-decorations)\n  - [Plugin Methods Exposed](#plugin-methods-exposed)\n\n## Installation\n\n```bash\n# npm\nnpm install hapi-nosql-mongoose mongoose\n\n# yarn\nyarn add hapi-nosql-mongoose mongoose\n```\n\n## Register as Hapi Plugin\n\n```javascript\nconst Mongoose = require('hapi-nosql-mongoose');\nconst schemas = require('./my/mongoose/schemas');\n\nawait server.register({\n    plugin: Mongoose,\n    options: {\n        uri: 'mongodb://localhost:27017/database',\n        config: {...},\n        schemas: {...}\n    }\n});\n```\n#### Options\n+ **uri**: a mongodb valid uri\n+ **config**: a javascript object with [mongoose options](http://mongoosejs.com/docs/connections.html#options)\n+ **schemas**: a javascript object with mongoose schema definitions\n\n#### Schema Definitions\nFor ease of use you can have a folder with all your schema definitions along an `index.js` file that exports all the schemas inside the folder. e.g:\n\n```bash\n-- /my/mongoose/schemas/\n  |-- index.js\n  |-- post.js\n  |-- user.js\n```\n\n```javascript\n// Post schema (post.js)\n'use strict';\n\nconst Schema = require('mongoose').Schema;\n\nconst Post = new Schema({\n    title: {\n        type: String,\n        trim: true\n    },\n    content: String,\n    authorId: {\n        type: String // referencing the User as you see fit\n    },\n    createdAt: {\n        type: Date,\n        'default': Date.now\n    }\n});\n\nmodule.exports = Post;\n```\n\n```javascript\n// User schema (user.js)\n'use strict';\n\nconst Schema = require('mongoose').Schema;\n\nconst User = new Schema({\n    uuid: {\n        type: String,\n        'default': uuid.v4 // using an uuid library\n    },\n    name: {\n        type: String,\n        trim: true\n    },\n    lastName: {\n        type: String,\n        trim: true\n    },\n    createdAt: {\n        type: Date,\n        'default': Date.now\n    }\n});\n\nmodule.exports = User;\n```\n\n```javascript\n// Exporter (index.js)\n'use strict';\n\nconst Post = require('./post');\nconst User = require('./user');\n\nconst schemas = {\n    Post,\n    User\n};\n\nmodule.exports = schemas\n```\n\n## Server Decorations\nThis plugin decorates the **server** object, adding a method called `mongoose:connector` that returns the full [Connector](lib/connector.js) object.\n\nUse the **Connector** object to get your models in your controllers like this:\n```javascript\nserver.route({\n    method: 'GET',\n    path: '/posts',\n    handler: async (request, h) =\u003e {\n\n        const Post = request.server['mongoose:connector'].getModel('Post');\n        // More code below\n    }\n});\n```\n\n## Plugin Methods Exposed\n+ **connection**: This gives you access to the Mongoose [Connection](http://mongoosejs.com/docs/api.html#Connection) Object.\n  ```javascript\n  server.route({\n    method: 'GET',\n    path: '/posts',\n    handler: async (request, h) =\u003e {\n\n        const MongooseConnection = request.server.plugins['hapi-nosql-mongoose'].connection;\n        // More code below\n    }\n  });\n  ```\n+ **mongoose**: This gives you access to the [Mongoose](http://mongoosejs.com/docs/api.html#mongoose_Mongoose) Object.\n  ```javascript\n  server.route({\n    method: 'GET',\n    path: '/posts',\n    handler: async (request, h) =\u003e {\n\n        const Mongoose = request.server.plugins['hapi-nosql-mongoose'].mongoose;\n        // More code below\n    }\n  });\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finiva%2Fhapi-nosql-mongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finiva%2Fhapi-nosql-mongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finiva%2Fhapi-nosql-mongoose/lists"}