javascript - Get latest data after delete/insert operation in couchbase Node.js -


i have difficult time latest bucket documents after operation (insert/delete). use node.js + express + couchbase, , here's code, derived official website. simple address book web-app , has 3 function: insert, show or delete contact.

after delete or insert operation, use res.redirect("\") reload page. problem is: show old data, after reload second time, shows up. don't know what's wrong here. can help?

/* home page. */ router.get('/', function(req, res) {    var query   = viewquery.from('view_people', 'by_id');    bucket.query(query, function(err, results){        return res.render('index', {people: results});    }); });  /* insert contact here */ router.post('/insert', function(req, res){     var name    = req.body.name;     var address = req.body.address;     var job     = req.body.job;     var age     = req.body.age;     bucket.insert(name, {     name    : name,     address : address,     job     : job,     age     : age     }, function(err, reply){         if(err) return res.send(err);         return res.redirect('/');     }) });  /* remove contact */ router.get('/remove', function(req, res){     var id = req.query.id;     bucket.remove(id, function(err, response){         if (err) {return res.send(err);}          return res.redirect('/');     }) });  module.exports = router; 

in couchbase, views consistent , looks using views, lag seeing. you'd better off getting document key if can, couchbase consistent. you'd performance if had meta-data object manual index of of user's contacts. when want contacts, pull meta-data object, parallelized bulk of objects want key. should perform , exact same thing. on top of that, have key pattern uniquely identifies object user.

another option have counter object per user key value counter. example have key pattern

username::contacts::counter

filled out, object's key might like

hernandez94::contacts::139

the counter upper bound of array of contacts user. recent contact, counter object, take integer, construct key , object. it'd fast. contacts, counter object , generate keys parallelized bulk get. again, that'd fast. no querying, raw speed scales consistently.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -