Skip to content

Instantly share code, notes, and snippets.

@tvalletta
Created June 15, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvalletta/9e26d61b0da6957071bda61ef9114f49 to your computer and use it in GitHub Desktop.
Save tvalletta/9e26d61b0da6957071bda61ef9114f49 to your computer and use it in GitHub Desktop.
Mongo connection using promises
'use strict';
const mongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/test';
mongoClient.connect(url)
.then(conn => {
return conn.collection('restaurants')
.find().limit(10).toArray()
.then(out => console.log(out))
.then(() => conn.close())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment