{"id":25445801,"url":"https://github.com/divmgl/mongoose-harmony-gridfs","last_synced_at":"2025-05-16T06:09:19.748Z","repository":{"id":25126649,"uuid":"28548449","full_name":"divmgl/mongoose-harmony-gridfs","owner":"divmgl","description":"Mongoose plugin for GridFS based on ES6 Harmony","archived":false,"fork":false,"pushed_at":"2015-01-01T22:12:59.000Z","size":164,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-10T13:53:48.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/divmgl.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":"2014-12-27T23:05:06.000Z","updated_at":"2018-12-20T00:09:34.000Z","dependencies_parsed_at":"2022-08-19T07:40:09.817Z","dependency_job_id":null,"html_url":"https://github.com/divmgl/mongoose-harmony-gridfs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divmgl%2Fmongoose-harmony-gridfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divmgl%2Fmongoose-harmony-gridfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divmgl%2Fmongoose-harmony-gridfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divmgl%2Fmongoose-harmony-gridfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/divmgl","download_url":"https://codeload.github.com/divmgl/mongoose-harmony-gridfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478193,"owners_count":22077676,"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":[],"created_at":"2025-02-17T16:50:18.745Z","updated_at":"2025-05-16T06:09:19.714Z","avatar_url":"https://github.com/divmgl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"mongoose-harmony-gridfs\n=======================\n\nMongoose plugin for GridFS based on ES6 Harmony\n\n## Purpose\nStore large documents in a MongoDB database using Mongoose with a painless syntax. This project should only be used with generator heavy projects, such as Koa projects.\n\n**This project will only work with Node \u003e0.11.**\n\n## Installation\n\nYou can download this plug-in through NPM.\n\n```node\nnpm install mongoose-harmony-gridfs \n```\n\n## Usage\n\nYou must attach this plug-in to your schema to begin using GridFS. Once the plug-in has been attached, all new schema instances will contain GridFS functionality.\n\n```javascript\nvar mongoose = require('mongoose');\nvar plugin   = require('mongoose-harmony-gridfs');\n\nvar profileSchema = mongoose.Schema({\n    name: String,\n    joinedOn: Date\n});\n\nvar settings = {\n    // These are the keys that will be stored in GridFS\n    keys: ['photo', 'thumbnail']\n};\n\nprofileSchema.plugin(plugin, settings); // Attach GridFS\nvar Profile = mongoose.model('Profile', profileSchema); // Ready to use GridFS\n\nvar user = new Profile() // Has GridFS functionality\n\n```\n\nYou can now access GridFS stores by using the keys you've set up in your schema.\n\n```javascript\nvar photo = yield user.photo;\n```\n\nPlease be wary of key usage. Your original schema **should not contain the same keys as the ones included in the plug-in**.\n\n### Settings\n\nYou can configure the plug-in by providing a settings object. At minimum, a `key` property will be required in order for the plug-in to function.\n\n* `key`: Array of strings that determine what keys will be used by the plug-in.\n* `bucket`: String that determines what GridFS repository should be used. By default it is `'fs'`.\n* `linkPropertyName`: String that determines what the property that is responsible for linking files will be named. By default it is `'_gfs'`.\n\n## CRUD operations\n### Saving\nOnce you've created a new instance, you can start saving buffers right away.\n```javascript\nvar user = new Profile()\nvar data = \"This is a random string!\";\nuser.photo = { buffer: data }; // This sends document information immediately to the database\n```\nInformation is sent to the database immediately. This plug-in will convert all data in the `buffer` property to a buffer that can be written to a GridFS store. Any existing information that was previously stored in the database is removed and replaced with the new buffer.\n\nYou can also store metadata regarding your file when saving to the database.\n\n```javascript\nvar data = { buffer: \"This is a random string!\", metadata: { user: \"mike\", id: 23415 } };\nuser.photo = data;\n```\n\n### Loading\nIf you can yield values because you are calling from a generator, you can yield for a database value. This will return a buffer with all contents in the file.\n```javascript\nvar photo = yield user.photo;\n```\nIf you need to provide error handling, you can wrap this statement in a try/catch.\n```javascript\nvar photo;\ntry {\n    photo = yield user.photo;\n} catch (err){\n    // Do something with the error\n}\n```\nIf you are operating within a function, you can use Q's done function to retrieve the information in a callback. Similarly, you can use the fail function to catch errors.\n```javascript\nvar promise = user.photo;\nvar photo;\npromise.done(function(data){\n    photo = data;\n}).fail(function(err){\n    throw err;\n});\n```\nIf you have stored metadata with your file, you can retrieve metadata information by using the `metadata(key)` method, which also returns a Q promise.\n```javascript\nvar metadata = yield user.metadata('photo');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivmgl%2Fmongoose-harmony-gridfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivmgl%2Fmongoose-harmony-gridfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivmgl%2Fmongoose-harmony-gridfs/lists"}