mongocache
v0.1.2
Published
Superfast cached/indexed queries from MongoDB!
Downloads
1
Readme
mongocache
Gets ALL documents (only selected keys) from MongoDB and keeps them updated with oplog. Also indexes collections, providing instantenous queries. Uses native MongoDB client, so it's superfast.
Especially useful if need to maintain and query complex tree hierarchies.
installation
npm install mongocache --save
usage
var mongocache = require('mongocache')
var dbcache = mongocache({
dbname: {
levels: {
select: '_id parent name', // only keep these keys
index: 'parent' // index 'parent' -value
}
}
})
setInterval(function () {
// get all docs
dbcache.dbname.levels.getAll(function (docs) {
console.log(docs)
})
// find by _id
dbcache.dbname.levels.findById('507f1f77bcf86cd799439011', function (doc) {
console.log(doc)
})
// find by indexed key ('parent' === '507f1f77bcf86cd799439011')
dbcache.dbname.levels.find('parent', '507f1f77bcf86cd799439011', function (docs) {
console.log(docs)
})
// find first by indexed key ('parent' === '507f1f77bcf86cd799439011')
dbcache.dbname.levels.findOne('parent', '507f1f77bcf86cd799439011', function (doc) {
console.log(doc)
})
}, 1000)