Video 96: Async/Await: Part II
This commit is contained in:
parent
76646facde
commit
cd08113b6e
@ -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)
|
||||||
})
|
})
|
||||||
|
@ -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)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user