Created
March 26, 2014 07:12
-
-
Save hajovsky/9778146 to your computer and use it in GitHub Desktop.
how to thunkify the mongodb native
This file contains 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
// npm install mongodb thunkify-wrap co | |
var mongo = require('mongodb'); | |
var t = require('thunkify-wrap'); | |
var co = require('co'); | |
co(function*(){ | |
var db = yield t(mongo.MongoClient.connect)('mongodb://127.0.0.1:27017/test'); | |
var items = db.collection('items'); | |
// cleanup | |
yield t(items.remove, items)(); | |
// insert some records | |
var record1 = yield t(items.insert, items)({lorem: "ipsum"}); | |
var record2 = yield t(items.insert, items)({lorem: "dolor"}); | |
var record3 = yield t(items.insert, items)({lorem: "sit amet"}); | |
// read it | |
var count = yield t(items.count, items)(); | |
var records = yield t(items.find().toArray, items)(); | |
console.log(count, records); | |
db.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much. Monk.js is very very old. And mongoose is shemalike.