Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose find one and update with new field

//                                                         V--- THIS WAS ADDED
Cat.findOneAndUpdate({age: 17}, {$set:{name:"Naomi"}}, {new: true}, (err, doc) => {
    if (err) {
        console.log("Something wrong when updating data!");
    }

    console.log(doc);
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongoose #find #update #field
ADD COMMENT
Topic
Name
7+7 =