{"id":15688424,"url":"https://github.com/quen2404/mongo-gridfs","last_synced_at":"2025-05-06T21:07:27.307Z","repository":{"id":48315221,"uuid":"149468451","full_name":"quen2404/mongo-gridfs","owner":"quen2404","description":"Uses the native GridFSBucket from the new MongoDB Driver and wrap it as Promise","archived":false,"fork":false,"pushed_at":"2021-08-02T04:18:15.000Z","size":244,"stargazers_count":8,"open_issues_count":17,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T10:51:51.406Z","etag":null,"topics":["async","es6","gridfs","gridfs-bucket","gridfsbucket","mongo","mongodb","mongoose","native-promise","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quen2404.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-09-19T15:01:39.000Z","updated_at":"2022-08-05T11:00:28.000Z","dependencies_parsed_at":"2022-09-20T23:20:56.279Z","dependency_job_id":null,"html_url":"https://github.com/quen2404/mongo-gridfs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quen2404%2Fmongo-gridfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quen2404%2Fmongo-gridfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quen2404%2Fmongo-gridfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quen2404%2Fmongo-gridfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quen2404","download_url":"https://codeload.github.com/quen2404/mongo-gridfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252394502,"owners_count":21740854,"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":["async","es6","gridfs","gridfs-bucket","gridfsbucket","mongo","mongodb","mongoose","native-promise","nodejs","typescript"],"created_at":"2024-10-03T17:59:46.910Z","updated_at":"2025-05-06T21:07:27.286Z","avatar_url":"https://github.com/quen2404.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongo-gridfs\n\nThis is a simple wrapper for the new [MongoDB GridFSBucket API](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/streaming/).\n\nThe old GridStore-API is now [deprecated](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/gridstore/).\n\n\n## How to install\n\nThat is simple\n\n`npm install mongo-gridfs`\n\nOR\n\n`yarn add mongo-gridfs`\n\n## Usage\n\n### With MongoClient\n\n```js\nconst mongoDBConnection = await MongoClient.connect('mongodb://localhost:27017/files');\nlet gridFS = new MongoGridFS(mongoDBConnection, \"attachments\");\ngridFS.findById(\"59e085f272882d728e2fa4c2\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n\n```\n\n### With Mongoose\n\n```js\nconst mongooseConnection = await Mongoose.connect('mongodb://localhost:27017/files');\nlet gridFS = new MongoGridFS(mongooseConnection.db, \"attachments\");\ngridFS.findById(\"59e085f272882d728e2fa4c2\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n\n```\n\n\n## Methods\n\n### findById\n\nBy this method you will simple get the meta-object from the MongoDB as a Promise-Object.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\n```js\ngridFS.findById(\"59e085f272882d728e2fa4c2\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n```\n\n### downloadFile\n\nYou will get the file simple written to the filesystem directly from the Database.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\n```js\ngridFS.downloadFile(\"59e085f272882d728e2fa4c2\", {\n    filename: \"test.gif\",\n    targetDir: \"/tmp\"\n}).then((downloadedFilePath) =\u003e {\n    console.log(downloadedFilePath);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n```\n\n### readFileStream\n\nYou will get a GridFSBucketReadStream as Promise.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\nThis method is very useful, to stream the content directly to the user.\n\nFor example with express:\n```js\nreturn gridFS.readFileStream(req.params.id).then((item) =\u003e {\n    item\n    .once(\"error\", () =\u003e {\n        return res.status(400).end();\n    }).pipe(res);\n}).catch(() =\u003e res.status(500));\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquen2404%2Fmongo-gridfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquen2404%2Fmongo-gridfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquen2404%2Fmongo-gridfs/lists"}