Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mongdb client v3 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand All @@ -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)
})
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"main": "./node/index",
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--compilers js:babel-core/register
--require babel-core/register