Advertisement
Guest User

Untitled

a guest
Nov 5th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Q = require('q');
  2. var mongo = require('mongodb'),
  3.   Server = mongo.Server,
  4.   Db = mongo.Db;
  5.  
  6. var server = new Server('localhost', 27017, {auto_reconnect: true});
  7. var db_ = new Db('annotedw', server, {safe: true});
  8.  
  9. Q.ncall(db_.open, db_).then(
  10.     function(db) {
  11.         return Q.ncall(db.collection, db, 'corpus');
  12.     }
  13. )
  14. .then(
  15.     function(coll) {
  16.         var cursor = coll.find();
  17.         return cursor;
  18.     }
  19. )
  20. .then(function(cursor) {
  21.     cursor.each(function(err, item) {
  22.         if(item != null) {
  23.             console.log(item.name);
  24.         } else {
  25.             db_.close();
  26.         }
  27.     });
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement