MongoDB Tutorial #13 - Updating Records

preview_player
Показать описание
Hey ninjas, in this MongoDB tutorial for beginners, we'll take a look how to update records already saved to the database using update() and findOneAndUpdate().

----- COURSE LINKS:

---------------------------------------------------------------------------------------------

========== PSD to WordPress Playlist ==========

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

Dude! Pls create a tutorial of MongoDB and Node.js but without using mocha, maybe creating a basic CRUD could help at the end of all the training. Thank you so much professor Shaun.

pablofonseca
Автор

I specified "_id" in addition to "name" in " 'Mario', _id: char._id}, {name: 'Luigi'}).then() ", otherwise, the updating record test would fail.

annez
Автор

the async update's response comes back with the updated record, is there a reason why we need to separately find it again? I could just write my assertion w/ that

idontwhy
Автор

Why is it not using .toString for find the id?

alvaronieto
Автор

how to add something to a record in mongodb?

swagz
Автор

Hi Ninjamaster! It fails when running :
db.mariochars.findOneAndUpdate({name:"Mario"}, {"name":"Luigi"});
in mongo shell, it says
"Error: the update operation document must contain atomic operators
But this one works:
db.mariochars.findOneAndUpdate({name:"Mario"}, {$set: {"name":"Luigi"}});

chenxuanwang
Автор

should use useFindAndModify: false to get ride of warning. like this mongoose.connect("mongodb://localhost/testaroo",
{
useNewUrlParser: true,
useFindAndModify: false
});

gmlinns
Автор

this tutorial could have been improved by not using mocha

ChrisFotosMusic