pro-mern-stack icon indicating copy to clipboard operation
pro-mern-stack copied to clipboard

Async Await Paradigm

Open KhalilMohammad opened this issue 8 years ago • 2 comments

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 avatar Jul 23 '17 20:07 KhalilMohammad

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 avatar Jul 23 '17 20:07 KhalilMohammad

It is similar to generator paradigm

KhalilMohammad avatar Jul 23 '17 21:07 KhalilMohammad