From 39ebea883adf4fc9fa7ad017a92cba700f49c00f Mon Sep 17 00:00:00 2001 From: Thee Sritabtim Date: Sun, 9 Feb 2020 21:53:22 +0700 Subject: [PATCH] support mongdb client v3 --- README.md | 2 ++ lib/index.js | 7 ++++--- package.json | 4 ++-- test/mocha.opts | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7794310..93b1d78 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ MongoDB standalone caching library for Node.JS and also cache engine for [cacheman](https://github.com/cayasso/cacheman). +Version 2 supports mongodb client version 3, for mongodb client version 2 use version 1 + ## Instalation ``` bash diff --git a/lib/index.js b/lib/index.js index badebed..c41617e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -70,7 +70,7 @@ export default class MongoStore { this.compression = options.compression || false this.ready = thunky((cb) => { function createIndex(err, db) { - db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => { + db.collection(coll).ensureIndex({ expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => { cb(err, db) }) } @@ -81,10 +81,11 @@ export default class MongoStore { return opt }, Object.assign({}, options)) - MongoClient.connect(conn, mongoOptions, (err, db) => { + MongoClient.connect(conn, mongoOptions, (err, client) => { + const db = client.db() if (err) return cb(err) createIndex(null, (this.client = db)) - db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => { + db.collection(coll).ensureIndex({ expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => { cb(err, db) }) }) diff --git a/package.json b/package.json index e40bbed..0c94c1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cacheman-mongo", - "version": "1.0.4", + "version": "2.0.0", "description": "MongoDB standalone caching library for Node.JS and also cache engine for cacheman", "author": "Jonathan Brumley ", "main": "./node/index", @@ -24,7 +24,7 @@ "pre-commit": "^1.1.2" }, "dependencies": { - "mongodb": "^2.1.4", + "mongodb": "^3.5.2", "mongodb-uri": "^0.9.7", "thunky": "^0.1.0" }, diff --git a/test/mocha.opts b/test/mocha.opts index ccd1f09..208d511 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1 @@ ---compilers js:babel-core/register +--require babel-core/register \ No newline at end of file