keyv-mongo-gridfs
v1.0.11
Published
MongoDB storage adapter for Keyv using Mongodb GridFS for value storage
Downloads
38
Maintainers
Readme
keyv-mongo-gridfs
MongoDB storage adapter for Keyv with GridFS support
MongoDB storage adapter for Keyv.
This adapter is written to support Mongodb GridFS. It stores all values in MongoDB GridFS. Values can be either string, buffer or json serializable objects.
Uses TTL indexes to automatically remove expired documents. However, TTL is not natively supported for GridFS by MongoDB so TTL is implemented with clearExpired()
function by this library. You use setInterval
on clearExpired()
function to automatically remove expired files from GridFS. You decide the interval at which you want to run it.
This module also provides clearUnusedFor(seconds)
method to clear files which not accessed for certain files. For example if you want to clear files not used in last 1 day, you can run clearUnusedFor(86400)
.
Install
npm install --save keyv keyv-mongo-gridfs
Usage
const Keyv = require('keyv');
const keyv = new Keyv('mongodb://user:pass@localhost:27017');
keyv.on('error', handleConnectionError);
You can specify the database name, by default 'keyv-file-cache'
is used.
e.g:
const keyv = new Keyv('mongodb://user:pass@localhost:27017', { db: 'example-keyv-cache', readPreference: "primary" });
License
MIT © Aditya Patadia