-
-
Save PaulGuo/a50deadc3fd45ff378ea 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
import Promise from 'bluebird' | |
import MongoDB from 'mongodb' | |
Promise.promisifyAll(MongoDB) | |
async function findEveryone(db) { | |
const people = db.collection('people') | |
const everyone = await people.find().toArrayAsync() | |
return everyone.map( x => x.name ) | |
} | |
(async function run() { | |
try { | |
var db = await MongoDB.MongoClient.connectAsync('mongodb://localhost/test') | |
const everyone = await findEveryone(db) | |
console.log(everyone) | |
} catch (e) { | |
console.log('Something went wrong', e) | |
} finally { | |
db && db.close() | |
} | |
})() |
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
{ | |
"name": "bluebird-async-await", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "./node_modules/.bin/babel-node --experimental --optional bluebirdCoroutines index.js" | |
}, | |
"author": "", | |
"license": "WTFPL", | |
"dependencies": { | |
"babel": "^4.7.16", | |
"bluebird": "^2.9.14", | |
"mongodb": "^1.4.34" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment