mongodb - Can't return the value of collection.findOne() -


i'm using monk mongodb driver, , want return value of collection.findone() render mypost response parameter.

this code:

//show single post router.get('/show/:id', function(req, res, next){     var mycategories = []     var mypost = {};     var posts = db.get('posts');     var categories = db.get('categories');     posts.findone({_id: req.params.id}, function(err, post){          });      console.log(mypost);      categories.find({}, {}, function(err, categories) {         (i=0; i<categories.length; i++) {               mycategories[i] = categories[i];             }     });     res.render('show', {             'pagetitle': mypost.title,             'categories': mycategories,             'post': mypost          }); 

//show single post router.get('/show/:id', function(req, res, next){   var mycategories = []   var mypost = {};   var posts = db.get('posts');   var categories = db.get('categories');   posts.findone({_id: req.params.id}, function(err, post){       //success param post not post    console.log(mypost, post);     categories.find({}, {}, function(err, categories) {     (i=0; i<categories.length; i++) {       mycategories[i] = categories[i];     }      //you cant access outside callback       res.render('show', {       'pagetitle': post.title,       'categories': mycategories,       'post': post      });    });    });   }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -