Created
October 6, 2017 14:46
-
-
Save ortense/94e06f0aa2396d0f18b4639cdc5cbcbf to your computer and use it in GitHub Desktop.
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
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