Created
September 9, 2011 11:39
-
-
Save Raynos/1205995 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = new Db('node-mongo-blog', new Server(host, port, {}), {native_parser:true}); | |
var blogstack = middleware(function(db, data, next) { | |
db.open(function(err, db) { | |
data.db = db; | |
next(); | |
}); | |
}, function(db, data, next) { | |
db.dropDatabase(function(err, result) { | |
next(); | |
}); | |
}, function(db, data, next) { | |
db.collection('authors', function(err, collection) { | |
data.collection = collection; | |
next(); | |
}); | |
}, function(db, data, next) { | |
data.authors = {}; | |
collection.insert([{'name':'William Shakespeare', 'email':'[email protected]', 'age':587}, | |
{'name':'Jorge Luis Borges', 'email':'[email protected]', 'age':123}], function(err, docs) { | |
docs.forEach(function(doc) { | |
data.authors[doc.name] = doc; | |
}); | |
next(); | |
}); | |
}, function(db, data, next) { | |
data.collection.find({}, {'sort':[['age', 1]]}, function(err, cursor) { | |
data.cursor = cursor; | |
next(); | |
}); | |
}, function(db, data, next) { | |
data.cursor.each(function(err, author) { | |
authorStack.handle(author, {}); | |
}); | |
}); | |
// var authorStack = ... | |
blogstack.handle(db, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment