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.
var mongocache = require('mongocache')
var dbcache = mongocache({
dbname: {
levels: {
select: '_id parent name',
index: 'parent'
}
}
})
setInterval(function () {
dbcache.dbname.levels.getAll(function (docs) {
console.log(docs)
})
dbcache.dbname.levels.findById('507f1f77bcf86cd799439011', function (doc) {
console.log(doc)
})
dbcache.dbname.levels.find('parent', '507f1f77bcf86cd799439011', function (docs) {
console.log(docs)
})
dbcache.dbname.levels.findOne('parent', '507f1f77bcf86cd799439011', function (doc) {
console.log(doc)
})
}, 1000)