Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http')
  2. , mongoose = require('mongoose')
  3. , asyncblock = require('asyncblock')
  4. , Schema = mongoose.Schema;
  5.  
  6. var PeopleSchema = new Schema({
  7.     name : String,
  8.     age : Number,
  9.     birth : Date
  10. });
  11.  
  12. mongoose.model('people', PeopleSchema);
  13. People = mongoose.model('people');
  14.  
  15. mongoose.connect('mongodb://localhost/people');
  16.  
  17. http.createServer(function (req, res) {
  18.  
  19.     res.writeHead(200, {
  20.         'Content-Type': 'text/plain'
  21.     });
  22.  
  23.     asyncblock(function(flow){
  24.         person = new People;
  25.         person.name = 'Testing Async';
  26.         person.age = 22;
  27.         person.birth = new Date()
  28.  
  29.         person.save(function(err){
  30.                 if(err) throw err;
  31.                 res.write("Finished db stuff\n");
  32.                 flow.add('goOn');
  33.         });
  34.  
  35.         flow.wait('goOn');
  36.         res.write('Person inserted.');
  37.         res.end();
  38.     });
  39.  
  40. }).listen(1337);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement