Correct handling of async Mongo actions in Node Promise
I have a function which performs multiple Mongo actions, and the last action is to close the database after all other actions have completed. I was fairly confident of my handling of the issue, but I have had some external comments raise concerns, and I wanted to verify if my solution is correct. A suggested solution: function updateDatabase (name, token) { return new Promise((resolve, reject) => { MongoClient.connect(MONGODB_URL) .then( (database) => { return database.collection('testCollection').update({name}, {$pull: {tokens: {$in: [token]}}}) .then( () => { database.collection('log')