1
0

Video 96: Async/Await: Part II

This commit is contained in:
JayWll 2020-02-23 16:46:50 -07:00
parent 76646facde
commit cd08113b6e
2 changed files with 33 additions and 11 deletions

View File

@ -1,11 +1,23 @@
require('../src/db/mongoose') require('../src/db/mongoose')
const Task = require('../src/models/task') const Task = require('../src/models/task')
Task.findByIdAndDelete('5e52f573b7d229017fe21321').then((task) => { // Task.findByIdAndDelete('5e52f573b7d229017fe21321').then((task) => {
console.log(task) // console.log(task)
return Task.countDocuments({ completed: false }) // return Task.countDocuments({ completed: false })
}).then((result) => { // }).then((result) => {
console.log(result) // console.log(result)
// }).catch((e) => {
// console.log(e)
// })
const deleteTaskAndCount = async (id) => {
const task = await Task.findByIdAndDelete(id)
const count = await Task.countDocuments({ completed: false })
return count
}
deleteTaskAndCount('5e489156e9232d006872395e').then((count) => {
console.log(count)
}).catch((e) => { }).catch((e) => {
console.log(e) console.log(e)
}) })

View File

@ -1,13 +1,23 @@
require('../src/db/mongoose') require('../src/db/mongoose')
const User = require('../src/models/user') const User = require('../src/models/user')
// 5e519e3404357c00d0777aee // User.findByIdAndUpdate('5e52f2612f736700e5a20797', { age: 1 }).then((user) => {
// console.log(user)
// return User.countDocuments({ age: 1 })
// }).then((result) => {
// console.log(result)
// }).catch((e) => {
// console.log(e)
// })
User.findByIdAndUpdate('5e52f2612f736700e5a20797', { age: 1 }).then((user) => { const updateAgeAndCount = async (id, age) => {
console.log(user) const user = await User.findByIdAndUpdate(id, { age })
return User.countDocuments({ age: 1 }) const count = await User.countDocuments({ age })
}).then((result) => { return count
console.log(result) }
updateAgeAndCount('5e52f2612f736700e5a20797', 2).then((count) => {
console.log(count)
}).catch((e) => { }).catch((e) => {
console.log(e) console.log(e)
}) })