• Reading from nested doc in mongoose nodejs

    abemassry        
    0 Likes0 Commentsjavascript

    app.get('/code/:id', function(req, res){
    
        if (req.user) {
          var username = req.user.username;
        }
    
        //if (app.requireAuth === true && req.loggedIn === false)
          //res.redirect('/auth/twitter');
    
        //get the example
        models.codes.findById(req.params.id, function(err, data){
          if (data) {
            models.users.findOne({name: username}, function(err, userdata){
             //render the view page
             res.render('code.jade', {
                 locals: {
                   title: data.title,
                   page: '',
                   code: data,
                   user: username,
                   userdata: userdata
                 }
             });
            });
          } else {
            res.redirect('/404');
          }
    
        });
      });
    

Comments (0)