vasansr / pro-mern-stack

Code Listing for the book Pro MERN Stack
http://www.apress.com/in/book/9781484226520
343 stars 159 forks source link

Async Await Paradigm #22

Open KhalilMohammad opened 7 years ago

KhalilMohammad commented 7 years ago

In ch-6 ,You explained 4 different paradigm for dealing with MongoDb. I think Es7 async await pattern is the most simple approach. Babel also provides Es2017 preset. I think you should include this paradigm in the book and make it default .

KhalilMohammad commented 7 years ago

const testWithAsyncAwait = async () => { let db = await MongoClient.connect('mongodb://localhost/playground'); try { const result = await db.collection('employees').insertOne({ id: 1, name: 'C. Generator' }); console.log('Result of insert:', result.insertedId); const docs = await db.collection('employees').find({ id: 1 }).toArray(); console.log('Result of find:', docs); db.close(); } catch (err) { console.log('ERROR', err); } }

KhalilMohammad commented 7 years ago

It is similar to generator paradigm