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')
const Task = require('../src/models/task')
Task.findByIdAndDelete('5e52f573b7d229017fe21321').then((task) => {
console.log(task)
return Task.countDocuments({ completed: false })
}).then((result) => {
console.log(result)
// Task.findByIdAndDelete('5e52f573b7d229017fe21321').then((task) => {
// console.log(task)
// return Task.countDocuments({ completed: false })
// }).then((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) => {
console.log(e)
})

View File

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