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) const db = client.db(databaseName)
// db.collection('users').findOne({ _id: new ObjectID('5db632720a8c580049920f36') }, (error, user) => { // db.collection('users').updateOne({
// if (error) { // _id: new ObjectID("5db5ee43fc565d010091bda4")
// return console.log('Unable to fetch') // }, {
// $inc: {
// age: 1
// } // }
// // }).then((result) => {
// console.log(user) // console.log(result)
// }).catch((error) => {
// console.log(error)
// }) // })
// db.collection('users').find({ age: 38 }).toArray((error, users) => { db.collection('tasks').updateMany({
// console.log(users) completed: false
// }) }, {
$set: {
db.collection('tasks').findOne({ _id: new ObjectID('5db5f0ef9d71180110fd3162') }, (error, task) => { completed: true
console.log(task) }
}) }).then((result) => {
console.log(result.modifiedCount)
db.collection('tasks').find({ completed: false }).toArray((error, tasks) => { }).catch((error) => {
console.log(tasks) console.log(error)
}) })
}) })