Skip to content

Instantly share code, notes, and snippets.

@PaulGuo
Forked from fxg42/index.js
Last active August 29, 2015 14:19
Show Gist options
  • Save PaulGuo/a50deadc3fd45ff378ea to your computer and use it in GitHub Desktop.
Save PaulGuo/a50deadc3fd45ff378ea to your computer and use it in GitHub Desktop.
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()
}
})()
{
"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