I'm learning Mongoose and I can't find in the documentation, nor in other questions on this site, why updateMany()
needs to have a .then()
in the end to be executed.
As an example, here is the code I'm trying to run, aiming to change the rating of the movies made in 1992 and 2019.
Movie.updateMany({year: {$in: [1992,2019]}}, {rating: 'M'}).then(data => console.log(data));
These are the movies in question:
{ "_id" : ObjectId("6282e0d37a9a5a4851d465b1"), "title" : "Elton Pan", "year" : 2013, "score" : 10, "rating" : "M", "__v" : 0 }
{ "_id" : ObjectId("6282e0d37a9a5a4851d465b2"), "title" : "Pon Porom", "year" : 2019, "score" : 0, "rating" : "M", "__v" : 0 }
{ "_id" : ObjectId("6282e0d37a9a5a4851d465b3"), "title" : "The Night", "year" : 1992, "score" : 10, "rating" : "R", "__v" : 0 }
If I attempt to run the code without .then
in the end, nothing changes.
I have also seen people use this method without .then
in the end, which makes me wonder if I can't use it this way because of the version of Mongoose I'm using.
Just to clarify, I'm checking the results via the Mongo shell, and not attempting to retreive the results within the code.
Thanks in advance, and sorry for the noob question :)