1
0

Video 80: Updating Documents

This commit is contained in:
JayWll 2020-02-15 12:21:22 -07:00
parent c0feae36d5
commit ecfb5078b1

View File

@ -12,23 +12,27 @@ MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) =>
const db = client.db(databaseName)
// db.collection('users').findOne({ _id: new ObjectID('5db632720a8c580049920f36') }, (error, user) => {
// if (error) {
// return console.log('Unable to fetch')
// db.collection('users').updateOne({
// _id: new ObjectID("5db5ee43fc565d010091bda4")
// }, {
// $inc: {
// age: 1
// }
//
// console.log(user)
// }).then((result) => {
// console.log(result)
// }).catch((error) => {
// console.log(error)
// })
// db.collection('users').find({ age: 38 }).toArray((error, users) => {
// console.log(users)
// })
db.collection('tasks').findOne({ _id: new ObjectID('5db5f0ef9d71180110fd3162') }, (error, task) => {
console.log(task)
})
db.collection('tasks').find({ completed: false }).toArray((error, tasks) => {
console.log(tasks)
db.collection('tasks').updateMany({
completed: false
}, {
$set: {
completed: true
}
}).then((result) => {
console.log(result.modifiedCount)
}).catch((error) => {
console.log(error)
})
})