Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // using $.getJSON('/list', function(data){do stuff with data})
  2.  
  3. app.get('/list', function(req, res) {
  4.   var items = getList();
  5.   console.log('--- APP GET ---');
  6.   console.log(items);
  7.   res.json(items);
  8. });
  9. // had it before as res.json(getList()); but that didn't work either
  10.  
  11.  
  12. function getList(){
  13.   MongoClient.connect('mongodb://heroku:thinkfast@dogen.mongohq.com:10042/reservations', function(err, db){
  14.     if(err){
  15.       return console.error(err);
  16.     }
  17.  
  18.     var collection = db.collection('requests');
  19.  
  20.     collection.find({}).toArray(function (err, items){
  21.       if (err) {
  22.         return console.error(err);
  23.       }
  24.  
  25.       console.log(items);
  26.       return items;
  27.     });
  28.   });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement