Skip to content

Instantly share code, notes, and snippets.

@ortense
Created October 6, 2017 14:46
Show Gist options
  • Save ortense/94e06f0aa2396d0f18b4639cdc5cbcbf to your computer and use it in GitHub Desktop.
Save ortense/94e06f0aa2396d0f18b4639cdc5cbcbf to your computer and use it in GitHub Desktop.
const { MongoClient } = require('mongodb')
const Bluebird = require('bluebird')
const DBURL = 'mongodb://localhost/demo'
const COLNAME = 'demo'
MongoClient.connect(DBURL, { promiseLibrary: Bluebird })
.tap(() => console.log('Connected!'))
.then(async db => {
const result = await db.collection(COLNAME).insert({ value: Math.random() })
return result.ops
})
.map(({ _id, value }) => ({
id: _id.toString(),
value,
}))
.then(console.log)
.catch(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment