{"id":13455196,"url":"https://github.com/devconcept/multer-gridfs-storage","last_synced_at":"2025-10-25T19:46:57.368Z","repository":{"id":8745622,"uuid":"59609486","full_name":"devconcept/multer-gridfs-storage","owner":"devconcept","description":"🍃 GridFS storage engine for Multer to store uploaded files directly to MongoDb","archived":false,"fork":false,"pushed_at":"2024-02-19T16:27:07.000Z","size":2776,"stargazers_count":239,"open_issues_count":31,"forks_count":71,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-17T20:23:25.609Z","etag":null,"topics":["express","gridfs","gridfs-stream","mongodb","multer","multipart","storage-engine","upload"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/devconcept.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-05-24T21:21:22.000Z","updated_at":"2025-03-11T07:22:27.000Z","dependencies_parsed_at":"2024-01-23T17:05:05.744Z","dependency_job_id":"ca1314ba-f7e1-4a86-ba88-8c91a977bb1a","html_url":"https://github.com/devconcept/multer-gridfs-storage","commit_stats":{"total_commits":592,"total_committers":6,"mean_commits":98.66666666666667,"dds":0.2804054054054054,"last_synced_commit":"ec1803d8f65de4c45f317a537bf885d62d762581"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devconcept%2Fmulter-gridfs-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devconcept%2Fmulter-gridfs-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devconcept%2Fmulter-gridfs-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devconcept%2Fmulter-gridfs-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devconcept","download_url":"https://codeload.github.com/devconcept/multer-gridfs-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245235177,"owners_count":20582170,"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":["express","gridfs","gridfs-stream","mongodb","multer","multipart","storage-engine","upload"],"created_at":"2024-07-31T08:01:02.346Z","updated_at":"2025-10-25T19:46:57.288Z","avatar_url":"https://github.com/devconcept.png","language":"TypeScript","readme":"# Multer's GridFS storage engine\r\n\r\n[![Build Status][github-image]][github-url] [![Coverage Status][coveralls-image]][coveralls-url] ![Npm version][version-image] [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) ![Downloads][downloads-image] [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdevconcept%2Fmulter-gridfs-storage.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdevconcept%2Fmulter-gridfs-storage?ref=badge_shield) [![Gitter](https://badges.gitter.im/multer-gridfs-storage/community.svg)](https://gitter.im/multer-gridfs-storage/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\r\n\r\n[GridFS](https://docs.mongodb.com/manual/core/gridfs) storage engine for [Multer](https://github.com/expressjs/multer) to store uploaded files directly to MongoDb.\r\n\r\n## 🔥 Features\r\n\r\n- Compatibility with MongoDb versions 2 and 3.\r\n- Really simple api.\r\n- Compatible with any current Node.js version.\r\n- Caching of url based connections.\r\n- Compatible with Mongoose connection objects.\r\n- Promise support.\r\n- Generator function support. \r\n- Support for existing and promise based database connections.\r\n- Storage operation buffering for incoming files while the connection is opening.\r\n- Use it as a multer plugin or inside an express middleware function.\r\n- Builtin Typescript support.\r\n\r\n## 🚀 Installation\r\n\r\nUsing npm\r\n\r\n```sh\r\n$ npm install multer-gridfs-storage --save\r\n```\r\n\r\nBasic usage example:\r\n\r\n```javascript\r\nconst express = require('express');\r\nconst multer  = require('multer');\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\nconst url = 'mongodb://yourhost:27017/database';\r\n\r\n// Create a storage object with a given configuration\r\nconst storage = new GridFsStorage({ url });\r\n\r\n// Set multer storage engine to the newly created object\r\nconst upload = multer({ storage });\r\n\r\nconst app = express();\r\n\r\n// Upload your files as usual\r\napp.post('/profile', upload.single('avatar'), (req, res, next) =\u003e { \r\n    /*....*/ \r\n});\r\n\r\napp.post('/photos/upload', upload.array('photos', 12), (req, res, next) =\u003e {\r\n    /*....*/ \r\n});\r\n\r\napp.post('/cool-profile', upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'gallery', maxCount: 8 }]), (req, res, next) =\u003e {\r\n    /*....*/ \r\n});\r\n```\r\n\r\n## 📄 API\r\n\r\n### module(configuration): function\r\n\r\nThe module returns a function that can be invoked to create a Multer storage engine. It also works as a class. It is up to you to decide the best way to invoke it.\r\n\r\nCheck the [wiki][wiki] for an in depth guide on how to use this module.\r\n\r\n### Configuration\r\n\r\nThe configuration parameter is an object with the following properties.\r\n\r\n#### url\r\n\r\nType: `string`\r\n\r\nRequired if [`db`][db-option] option is not present\r\n\r\nAn url pointing to the database used to store the incoming files.\r\n\r\nWith this option the module will create a mongodb connection for you. It must be a standard mongodb [connection string][connection-string].\r\n\r\nIf the [`db`][db-option] option is specified this setting is ignored.\r\n\r\nExample:\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n    url: 'mongodb://yourhost:27017/database'\r\n});\r\n```\r\n\r\nThe connected database is available in the `storage.db` property.\r\n\r\nOn mongodb v3 the client instance is also available in the `storage.client` property.\r\n\r\n#### options\r\n\r\nType: object\r\n\r\nNot required\r\n\r\nThis setting allows you to customize how this module establishes the connection if you are using the [`url`][url-option] option. \r\n\r\nYou can set this to an object like is specified in the [`MongoClient.connect`][mongoclient-connect] documentation and change the default behavior without having to create the connection yourself using the [`db`][db-option] option.\r\n\r\n#### cache\r\n\r\nType: `boolean` or `string`\r\n\r\nNot required\r\n\r\nDefault value: `false`\r\n\r\nStore this connection in the internal cache. You can also use a string to use a named cache. By default caching is disabled. See [caching](#caching) to learn more about reusing connections.\r\n\r\n\u003e This option only applies when you use an url string to connect to MongoDb. Caching is not enabled when you create instances with a [database][db-option] object directly.\r\n\r\n#### db\r\n\r\nType: [`DB`][mongo-db] or `Promise`\r\n\r\nRequired if [`url`][url-option] option is not present\r\n\r\nThe database connection to use, or a promise that resolves with the connection object. Mongoose `Connection` objects are supported too.\r\n\r\nThis is useful to reuse an existing connection to create more storage objects.\r\n\r\nExample:\r\n\r\n```javascript\r\n\r\n// using a database instance\r\nconst client = await MongoClient.connect('mongodb://yourhost:27017');\r\nconst database = client.db('database');\r\nconst storage = new GridFsStorage({ db: database });\r\n\r\n// using a promise\r\nconst promise = MongoClient\r\n  .connect('mongodb://yourhost:27017')\r\n  .then(client =\u003e client.db('database'));\r\n  \r\nconst storage = new GridFsStorage({ db: promise });\r\n```\r\n\r\n```javascript\r\n// using Mongoose\r\n\r\nconst connection = mongoose.connect('mongodb://yourhost:27017/database');\r\n\r\nconst storage = new GridFsStorage({ db: connection });\r\n```\r\n\r\n```javascript\r\n// mongodb v2\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n \r\n// using a database instance\r\nconst database = await MongoClient.connect('mongodb://yourhost:27017/database');\r\nconst storage = new GridFsStorage({ db: database });\r\n\r\n// using a promise\r\nconst promise = MongoClient.connect('mongodb://yourhost:27017/database');\r\nconst storage = new GridFsStorage({ db: promise });\r\n```\r\n\r\n#### client\r\n\r\nIf you used the `db` option to initialize the storage engine you can also include the `client` generated by calling the `MongoClient.connect` method in this option.\r\n\r\nUsing promises is also supported\r\n\r\n```javascript\r\n// including the client in the storage\r\nconst client = await MongoClient.connect('mongodb://yourhost:27017');\r\nconst db = client.db('database');\r\nconst storage = new GridFsStorage({ db, client});\r\n\r\n// using a promise\r\nconst client = MongoClient.connect('mongodb://yourhost:27017');\r\nconst db = client.then(cl =\u003e cl.db('database'));\r\nconst storage = new GridFsStorage({ db, client});\r\n```\r\n\r\nUsing this feature is highly recommended in order to keep the storage in sync with the underlying connection status and to make your code more resilient to future changes in the mongodb library.\r\n\r\n#### file\r\n\r\nType: `function` or `function*`\r\n\r\nNot required\r\n\r\nA function to control the file storage in the database. Is invoked **per file** with the parameters `req` and `file`, in that order.\r\n\r\nThis module uses [`GridFSBucket`](http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html) to store files in the database falling back to [`GridStore`](http://mongodb.github.io/node-mongodb-native/3.1/api/GridStore.html) in case the previous class is not found like, for example, in earlier versions of MongoDb. \r\n\r\nBy default, naming behaves exactly like the default Multer disk storage, a 16 bytes long name in a hexadecimal format with no extension is generated for each file to guarantee that there are very low probabilities of collisions. You can override this by passing your own function.\r\n\r\nThe return value of this function is an object, or a promise that resolves to an object (this also applies to generators) with the following properties. \r\n\r\nProperty name | Description\r\n------------- | -----------\r\n`filename` | The desired filename for the file (default: 16 byte hex name without extension)\r\n`id` | An ObjectID to use as identifier (default: auto-generated)\r\n`metadata` | The metadata for the file (default: `null`)\r\n`chunkSize` | The size of file chunks in bytes (default: 261120)\r\n`bucketName` | The GridFs collection to store the file (default: `fs`)\r\n`contentType` | The content type for the file (default: inferred from the request)\r\n`aliases` | Optional array of strings to store in the file document's aliases field (default: `null`)\r\n`disableMD5` | If true, disables adding an md5 field to file data (default: `false`, available only on MongoDb \u003e= 3.1)\r\n\r\nAny missing properties will use the defaults. Also, note that each property must be supported by your installed version of MongoDb.\r\n\r\nIf you return `null` or `undefined` from the file function, the values for the current file will also be the defaults. This is useful when you want to conditionally change some files while leaving others untouched.\r\n\r\nThis example will use the collection `'photos'` only for incoming files whose reported mime-type is `image/jpeg`, the others will be stored using default values.\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://host:27017/database',\r\n  file: (req, file) =\u003e {\r\n    if (file.mimetype === 'image/jpeg') {\r\n      return {\r\n        bucketName: 'photos'\r\n      };\r\n    } else {\r\n      return null;\r\n    }\r\n  }\r\n});\r\nconst upload = multer({ storage });\r\n```\r\n\r\nThis other example names every file something like `'file_1504287812377'`, using the date to change the number and to generate unique values\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://host:27017/database',\r\n  file: (req, file) =\u003e {\r\n    return {\r\n      filename: 'file_' + Date.now()\r\n    };\r\n  }\r\n});\r\nconst upload = multer({ storage });\r\n```\r\n\r\nIs also possible to return values other than objects, like strings or numbers, in which case they will be used as the filename and the remaining properties will use the defaults. This is a simplified version of a previous example\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://host:27017/database',\r\n  file: (req, file) =\u003e {\r\n    // instead of an object a string is returned\r\n    return 'file_' + Date.now();\r\n  }\r\n});\r\nconst upload = multer({ storage });\r\n```\r\n\r\nInternally the function `crypto.randomBytes` is used to generate names. In this example, files are named using the same format plus the extension as received from the client, also changing the collection where to store files to `uploads`.\r\n\r\n```javascript\r\nconst crypto = require('crypto');\r\nconst path = require('path');\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nvar storage = new GridFsStorage({\r\n  url: 'mongodb://host:27017/database',\r\n  file: (req, file) =\u003e {\r\n    return new Promise((resolve, reject) =\u003e {\r\n      crypto.randomBytes(16, (err, buf) =\u003e {\r\n        if (err) {\r\n          return reject(err);\r\n        }\r\n        const filename = buf.toString('hex') + path.extname(file.originalname);\r\n        const fileInfo = {\r\n          filename: filename,\r\n          bucketName: 'uploads'\r\n        };\r\n        resolve(fileInfo);\r\n      });\r\n    });\r\n  }\r\n});\r\nconst upload = multer({ storage });\r\n```\r\n\r\n### File information\r\n\r\nEach saved file located in `req.file` and `req.files` contain the following properties in addition to the ones that Multer create by default. Most of them can be set using the [`file`][file-option] configuration.\r\n\r\nKey | Description\r\n--- | -----------\r\n`filename` | The name of the file within the database\r\n`metadata` | The stored metadata of the file\r\n`id` | The id of the stored file\r\n`bucketName` | The name of the GridFs collection used to store the file\r\n`chunkSize` | The size of file chunks used to store the file\r\n`size` | The final size of the file in bytes\r\n`md5` | The md5 hash of the file\r\n`contentType` | Content type of the file in the database\r\n`uploadDate` | The timestamp when the file was uploaded\r\n\r\nTo see all the other properties of the file object, check the Multer's [documentation](https://github.com/expressjs/multer#file-information).\r\n\r\n\u003e Do not confuse `contentType` with Multer's `mimetype`. The first is the value in the database while the latter is the value in the request. You could choose to override the value at the moment of storing the file. In most cases both values should be equal. \r\n\r\n### 📀 Caching\r\n\r\nYou can enable caching by either using a boolean, or a non-empty string in the [cache][cache-option] option, then, when the module is invoked again with the same [url][url-option] it will use the stored db instance instead of creating a new one.\r\n\r\nThe cache is not a simple object hash. It supports handling asynchronous connections. You could, for example, synchronously create two storage instances for the same cache one after the other and only one of them will try to open a connection. \r\n\r\nThis greatly simplifies managing instances in different files of your app. All you have to do now is to store a url string in a configuration file to share the same connection. Scaling your application with a load-balancer, for example, can lead to spawn a great number of database connections for each child process. With this feature no additional code is required to keep opened connections to the exact number you want without any effort.\r\n\r\nYou can also create named caches by using a string instead of a boolean value. In those cases, the module will uniquely identify the cache allowing for an arbitrary number of cached connections per url and giving you the ability to decide which connection to use and how many of them should be created. \r\n\r\nThe following code will create a new connection and store it under a cache named `'default'`.\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n    url: 'mongodb://yourhost:27017/database',\r\n    cache: true\r\n});\r\n```\r\n\r\nOther, more complex example, could be creating several files and only two connections to handle them.\r\n\r\n```javascript\r\n // file 1\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n   url: 'mongodb://yourhost:27017/database',\r\n   cache: '1'\r\n});\r\n\r\n// file 2\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n    url: 'mongodb://yourhost:27017/database',\r\n    cache: '1'\r\n});\r\n\r\n // file 3\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n   url: 'mongodb://yourhost:27017/database',\r\n   cache: '2'\r\n});\r\n\r\n// file 4\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\nconst storage = new GridFsStorage({\r\n    url: 'mongodb://yourhost:27017/database',\r\n    cache: '2'\r\n});\r\n```\r\n\r\nThe files 1 and 2 will use the connection cached under the key `'1'` and the files 3 and 4 will use the cache named `'2'`. You don't have to worry about managing connections anymore. By setting a simple string value the module manages them for you automatically.\r\n\r\nConnection strings are parsed and tested for similarities. In this example the urls are equivalent and only one connection will be created.\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\n\r\n// Both configurations are equivalent\r\n\r\nconst storage1 = new GridFsStorage({\r\n    url: 'mongodb://host1:27017,host2:27017/database',\r\n    cache: 'connections'\r\n});\r\n\r\nconst storage2 = new GridFsStorage({\r\n    url: 'mongodb://host2:27017,host1:27017/database',\r\n    cache: 'connections'\r\n});\r\n```\r\n\r\nOf course if you want to create more connections this is still possible. Caching is disabled by default so setting a `cache: false` or not setting any cache configuration at all will cause the module to ignore caching and create a new connection each time.\r\n\r\nUsing [options][options-option] has a particular side effect. The cache will spawn more connections only **when they differ in their values**. Objects provided here are not compared by reference as long as they are just plain objects. Falsey values like `null` and `undefined` are considered equal. This is required because various options can lead to completely different connections, for example when using replicas or server configurations. Only connections that are *semantically equivalent* are considered equal.\r\n\r\n### 🧰 Utility methods\r\n\r\n#### `generateBytes`\r\n\r\nA shortcut for `crypto.randomBytes` which uses promises instead of callbacks to generate names and return the value in a property called `filename`.\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\nconst {generateBytes} = GridFsStorage;\r\nconst result = await generateBytes();\r\n// result will be something like {filename: '37492f9fe13c350667350bcacf0e5b19'}\r\n```\r\n\r\n#### `fromStream`\r\n\r\nA function that pipe a readable stream to gridfs using the current storage configuration. Useful if you want to upload the received file in multiple storage devices.\r\n\r\n```javascript\r\nconst {GridFsStorage} = require('multer-gridfs-storage');\r\nconst multer = require('multer');\r\nconst upload = multer({ dest: 'uploads/' });\r\nconst app = express();\r\nconst storage = new GridFsStorage({url: 'mongodb://yourhost:27017/database'});\r\n\r\napp.post('/profile', upload.single('avatar'), function (req, res, next) {\r\n  const {file} = req;\r\n  const stream = fs.createReadStream(file.path);\r\n  storage.fromStream(stream, req, file)\r\n    .then(() =\u003e res.send('File uploaded'))\r\n    .catch(() =\u003e res.status(500).send('error'));\r\n});\r\n```\r\n\r\n#### Storage ready\r\n\r\nEach storage has a `ready` method that returns a promise. This allows you to watch for the MongoDb connection instead of using events. These two examples are equivalent.\r\n\r\n```javascript\r\n// Using event emitters\r\n\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://yourhost:27017/database'\r\n});\r\n\r\nstorage.on('connection', (db) =\u003e {\r\n  // Db is the database instance\r\n});\r\n\r\nstorage.on('connectionFailed', (err) =\u003e {\r\n  // err is the error received from MongoDb\r\n});\r\n```\r\n\r\n```javascript\r\n// Using the ready method\r\n\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://yourhost:27017/database'\r\n});\r\n\r\ntry {\r\n  const {db, client} = await storage.ready();\r\n  // db is the database instance\r\n  // client is the MongoClient instance\r\n} catch (err) {\r\n // err is the error received from MongoDb\r\n}\r\n```\r\n\r\nRemember that you don't need to wait for the connection to be ready to start uploading files. The module buffers every incoming file until the connection is ready and saves all of them as soon as possible.\r\n\r\nThe `ready` method is just a convenience function over code written using the `connection` events also with a  couple of advantages. If you set up a listener after the `connection` or  `connectionFailed` events are dispatched your code will not execute while using the `ready` method it will. The module keeps track of these events and resolves or rejects the promises accordingly. Promises in this case are more readable than events and more reliable.\r\n\r\n### ⚡ Events\r\n\r\nEach storage object is also a standard Node.js Event Emitter. This is done to ensure that some internal events can also be handled in user code.\r\n\r\n#### Event: `'connection'`\r\n\r\nThis event is emitted when the MongoDb connection is ready to use.\r\n\r\n*Event arguments*\r\n\r\n - result: Result is an object with the following properties:\r\n \r\n    `db`: The MongoDb database pointing to the database\r\n    \r\n    `client`: The MongoClient instance that holds the connection\r\n\r\n\r\nThis event is triggered at most once.\r\n\r\n#### Event: `'connectionFailed'`\r\n\r\nThis event is emitted when the connection could not be opened.\r\n\r\n - err: The connection error\r\n\r\nThis event only triggers at most once. \r\n\r\n\u003e Only one of the events `connection` or `connectionFailed ` will be emitted.\r\n\r\n#### Event: `'file'`\r\n\r\nThis event is emitted every time a new file is stored in the db. \r\n\r\n*Event arguments*\r\n\r\n - file: The uploaded file\r\n\r\n\r\n#### Event: `'streamError'`\r\n\r\nThis event is emitted when there is an error streaming the file to the database.\r\n\r\n*Event arguments*\r\n\r\n - error: The streaming error\r\n - conf: The failed file configuration\r\n\r\n\u003e Previously this event was named `error` but in Node `error` events are special and crash the process if one is emitted and there is no listener attached. You could choose to handle errors in an [express middleware][error-handling] forcing you to set an empty `error` listener to avoid crashing. To simplify the issue this event was renamed to allow you to choose the best way to handle storage errors.\r\n\r\n#### Event: `'dbError'`\r\n\r\nThis event is emitted when the underlying connection emits an error.\r\n\r\n \u003e Only available when the storage is created with the [`url`][url-option] option.\r\n\r\n*Event arguments*\r\n\r\n - error: The error emitted by the database connection\r\n\r\n## 📣 Notes\r\n\r\nWhen using the [`url`][url-option] feature with the option `{useUnifiedTopology:true}` to create a MongoDb connection like this:\r\n\r\n```javascript\r\nconst storage = new GridFsStorage({\r\n  url: 'mongodb://yourhost:27017/database',\r\n  options: {useUnifiedTopology: true},\r\n});\r\n``` \r\n \r\nIn this case the internal client always report that the connection is open even when is not. This is a known bug that you can track [here](https://jira.mongodb.org/browse/NODE-2234). \r\n\r\nIs recommended that you only use this option with a MongoDb version that has the bug resolved, otherwise the storage instance cannot track the connection status and features like buffering could not work properly in some scenarios. \r\n\r\n## 🧪 Test\r\n\r\nTo run the test suite, first install the dependencies, then run `npm test`:\r\n\r\n```bash\r\n$ npm install\r\n$ npm test\r\n```\r\n\r\nTests are written with the [ava](https://avajs.dev) testing framework.\r\n\r\nCode coverage thanks to [istanbul](https://istanbul.js.org/)\r\n\r\n```bash\r\n$ npm run coverage\r\n```\r\n\r\n## 📜 License\r\n\r\n[MIT](https://github.com/devconcept/multer-gridfs-storage/blob/master/LICENSE)\r\n\r\n[github-url]: https://github.com/devconcept/multer-gridfs-storage/actions\r\n[github-image]: https://github.com/devconcept/multer-gridfs-storage/actions/workflows/node.js.yml/badge.svg \"Build status\"\r\n[coveralls-url]: https://coveralls.io/github/devconcept/multer-gridfs-storage?branch=master\r\n[coveralls-image]: https://coveralls.io/repos/github/devconcept/multer-gridfs-storage/badge.svg?branch=master \"Coverage report\"\r\n[version-image]:https://img.shields.io/npm/v/multer-gridfs-storage.svg \"Npm version\"\r\n[downloads-image]: https://img.shields.io/npm/dm/multer-gridfs-storage.svg \"Monthly downloads\"\r\n\r\n[connection-string]: https://docs.mongodb.com/manual/reference/connection-string\r\n[mongoclient-connect]: http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#.connect\r\n[mongo-db]: http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html\r\n[error-handling]: https://github.com/expressjs/multer#error-handling\r\n\r\n[url-option]: #url\r\n[options-option]: #options\r\n[db-option]: #db\r\n[file-option]: #file\r\n[cache-option]: #cache\r\n[wiki]: https://github.com/devconcept/multer-gridfs-storage/wiki\r\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevconcept%2Fmulter-gridfs-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevconcept%2Fmulter-gridfs-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevconcept%2Fmulter-gridfs-storage/lists"}