Currently delving into the intricacies of Mongoose, I am perplexed as to why updateMany()
requires a .then()
at the end in order to be executed.
For instance, here is the snippet that I'm endeavoring to execute, with the intention of altering the rating of movies from 1992 and 2019:
Movie.updateMany({year: {$in: [1992,2019]}}, {rating: 'M'}).then(data => console.log(data));
The following 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 omit .then
at the end while running the code, no changes occur.
I have observed others utilizing this method without including .then
at the end, leading me to question whether my inability to do so stems from the version of Mongoose I'm working with.
To clarify, I am inspecting the outcomes via the Mongo shell instead of trying to retrieve the results within the code itself.
Thank you in advance for your assistance, and pardon my novice inquiry :)