From ecfb5078b193e49ec3bfc5a86984d6f8248a16de Mon Sep 17 00:00:00 2001 From: JayWll Date: Sat, 15 Feb 2020 12:21:22 -0700 Subject: [PATCH] Video 80: Updating Documents --- task-manager/mongodb.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/task-manager/mongodb.js b/task-manager/mongodb.js index a59da0a..19374f7 100644 --- a/task-manager/mongodb.js +++ b/task-manager/mongodb.js @@ -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) }) })