2020-02-23 22:53:45 +00:00
|
|
|
require('../src/db/mongoose')
|
|
|
|
const User = require('../src/models/user')
|
|
|
|
|
2020-02-23 23:46:50 +00:00
|
|
|
// 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)
|
|
|
|
// })
|
2020-02-23 22:53:45 +00:00
|
|
|
|
2020-02-23 23:46:50 +00:00
|
|
|
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)
|
2020-02-23 22:53:45 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
console.log(e)
|
|
|
|
})
|