Open KhalilMohammad opened 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);
}
}
It is similar to generator paradigm
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 .