{"id":22819522,"url":"https://github.com/bdfoster/blueprint-mongodb","last_synced_at":"2025-10-11T00:36:08.839Z","repository":{"id":147886253,"uuid":"72710204","full_name":"bdfoster/blueprint-mongodb","owner":"bdfoster","description":"Blueprint.js module for MongoDB","archived":false,"fork":false,"pushed_at":"2016-10-29T20:58:06.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T13:52:18.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bdfoster.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-03T04:57:24.000Z","updated_at":"2022-10-13T01:28:43.000Z","dependencies_parsed_at":"2023-05-27T20:00:29.400Z","dependency_job_id":null,"html_url":"https://github.com/bdfoster/blueprint-mongodb","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/bdfoster/blueprint-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdfoster%2Fblueprint-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdfoster%2Fblueprint-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdfoster%2Fblueprint-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdfoster%2Fblueprint-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdfoster","download_url":"https://codeload.github.com/bdfoster/blueprint-mongodb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdfoster%2Fblueprint-mongodb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005651,"owners_count":26083942,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-12T15:12:43.593Z","updated_at":"2025-10-11T00:36:08.796Z","avatar_url":"https://github.com/bdfoster.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"blueprint-mongodb\n=================\n\nA Blueprint.js module for MongoDB\n\n[![npm version](https://img.shields.io/npm/v/@onehilltech/blueprint-mongodb.svg)](https://www.npmjs.com/package/@onehilltech/blueprint-mongodb)\n[![Build Status](https://travis-ci.org/onehilltech/blueprint-mongodb.svg?branch=master)](https://travis-ci.org/onehilltech/blueprint-mongodb)\n[![Dependencies](https://david-dm.org/onehilltech/blueprint-mongodb.svg)](https://david-dm.org/onehilltech/blueprint-mongodb)\n[![Coverage Status](https://coveralls.io/repos/github/onehilltech/blueprint-mongodb/badge.svg?branch=master)](https://coveralls.io/github/onehilltech/blueprint-mongodb?branch=master)\n\n\nInstallation\n------------\n\n    npm install @onehilltech/blueprint-mongodb --save\n\nUsage\n-----\n\n### Configuration\n\nDefine the `mongodb.config.js` configuration file in your Blueprint.js application.\n\n```javascript\n// mongodb.config.js\n\nmodule.exports = {\n  defaultConnection: // Optional name of default connection [default is $default]\n  \n  connections: {     // Define one or more connections by name.    \n    $default: {\n      connstr:       // MongoDB connection string\n      options:  {    // mongoose connection options\n            \n      }      \n    }\n  }\n};\n```\n\n### Models\n\nModels represent the different collections stored in the \n[MongoDB](https://www.mongodb.com) database. The models are defined \nusing [Mongoose schemas](http://mongoosejs.com/docs/guide.html).\n\n```javascript\n// app/models/Person.js\n\nvar mongodb = require ('@onehilltech/blueprint-mongodb')\n  ;\n\n// use mongodb.Types to access mongoose.Types\n\nvar schema = mongodb.Schema ({\n  first_name: {type: String, required: true, trim: true},\n  last_name: {type: String, required: true, trim: true}\n});\n\nmodule.exports = mongodb.model ('person', schema);\n```\n\nAll models are defined on the default connection unless stated otherwise. To define\na model on a different connection, use the `modelOn()` function where the first parameter\nis the name of the connection as defined in `mongodb.config.js`, followed by the \nsame parameters for the `model()` function.\n\n### ResourceController\n\nThe `ResourceController` is a default implementation of a resource controller\nthat integrates with the Blueprint.js architecture. The `ResourceController`\ncan be used as-is, or extended to add domain-specific customizations.\n\n```javascript\nvar blueprint          = require ('@onehilltech/blueprint')\n  , mongodb            = require ('@onehilltech/blueprint-mongodb')\n  , ResourceController = mongodb.ResourceController\n  , Person             = require ('../models/Person')\n  ;\n    \nfunction PersonController () {\n  ResourceController.call (this, {name: 'person', model: Person});\n}\n\nblueprint.controller (PersonController, ResourceController)\n```\n\nThe resource controller exposes the following actions:\n\n| Action       | HTTP method | Body                       | Response\n|--------------|-------------|----------------------------|-----------------------------------|\n| create       | POST        | {\\\u003cresource\\\u003e: { values }} | {\\\u003cresource\\\u003e: { values }}        |\n| retrieve one | GET         | N/A                        | {\\\u003cresource\\\u003e: { values }}        |\n| retrieve all | GET         | N/A                        | {\\\u003cplural-resource\\\u003e: { values }} |   \n| update       | UPDATE      | {\\\u003cresource\\\u003e: { values }} | {\\\u003cresource\\\u003e: { values }}        |\n| delete       | DELETE      | N/A                        | `true` or `false`                 |\n\nFor example, the `PersonController` exposes the following actions:\n\n| Action       | HTTP method | Body                       | Response\n|--------------|-------------|----------------------------|-----------------------------------|\n| create | POST | `{person: { first_name: 'James', last_name: 'Hill }}` | `{person: {_id: 'id', first_name: 'James', last_name: 'Hill' }}` |\n| retrieve one | GET | N/A  | `{person: {_id: 'id', first_name: 'James', last_name: 'Hill' }}`  |\n| retrieve all | GET | N/A  | `{persons: [{_id: 'id', first_name: 'James', last_name: 'Hill' }]}` |   \n| update  | UPDATE | `{person: { first_name: 'John' }}` | `{person: {_id: 'id', first_name: 'John', last_name: 'Hill }}`        |\n| delete       | DELETE      | N/A                        | `true` or `false`                 |\n\n\n**Messaging Framework.** All actions on the default implementation of the\n`ResourceController` will generate the following events on Blueprint.js messaging \nframework.\n\n| Action | Event | Example |\n|--------|-------|---------|\n| create | [prefix.][name].created | [prefix.]person.created |\n| update | [prefix.][name].updated | [prefix.]person.updated |\n| delete | [prefix.][name].deleted | [prefix.]person.deleted |\n\nThe prefix in the event name is optional. It is defined by the `eventPrefix` property\npassed to the `ResourceController` constructor.\n \n### GridFSController\n\nThe `GridFSController` is a [Blueprint.js](https://github.com/onehilltech/blueprint) \nresource controller designed for [GridFS](https://docs.mongodb.com/manual/core/gridfs/) \nin [MongoDB](https://www.mongodb.com). The `GridFSController` support the following\noperations out-of-the-box: create, get, and delete. Currently, it does not\nsupport getting multiple resources and updating an existing resource. \n\nBecause `GridFS` is designed to store large files, the `GridFSController` assumes the \nclient is uploading a file, which can be a multi-part file. The controller handles this \nconcern automatically. It's just your responsibility to inform the controller of the \nparameter used for the upload, and what connection on the database to use for GridFS. \nBelow is an example `GridFSController` for storing images that use the default connection.\n\n```javascript\n'use strict';\n\nvar blueprint        = require ('@onehilltech/blueprint')\n  , mongodb          = require ('@onehilltech/blueprint-mongodb')\n  , GridFSController = mongodb.GridFSController\n  ;\n\nfunction ImageController () {\n  GridFSController.call (this, mongodb.getConnectionManager ().defaultConnection, {name: 'image'});\n}\n\nblueprint.controller (ImageController, GridFSController);\n\nmodule.exports = ImageController;\n```\n\nThis controller will extract the uploaded file from the `image` parameter.\nIn addition, it will create collections named `image.files` and `image.chunks`\nin the database associated with the connection. If you want to use a different \nconnection, then use the `getConnection(name)` method on the `ConnectionManager`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdfoster%2Fblueprint-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdfoster%2Fblueprint-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdfoster%2Fblueprint-mongodb/lists"}