Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb findoneandupdate return updated

//pass the {new: true} as the third option, if using mongodb driver use {returnOriginal: true}                                                      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);
});
Comment

mongodb findoneandupdate return new document

const update = await client.db('database').collection('col').findOneAndUpdate({
      'param': 'value'
    }, {
      $set: {
        'param': 'newvalue'
      }
    }, {
      returnDocument: 'after',
      projection: {
        param: 1
      }
    })
Comment

PREVIOUS NEXT
Code Example
Javascript :: rust read json file 
Javascript :: detect emoji in string javascript 
Javascript :: discord.js messageDelete 
Javascript :: livewire set model with javascript 
Javascript :: how to get innerhtml value in javascript 
Javascript :: object to formdata 
Javascript :: jquery select attribute 
Javascript :: truncate a string 
Javascript :: datatable 
Javascript :: mocha timeout 
Javascript :: js regex with variable 
Javascript :: install react router 
Javascript :: javascript expressions 
Javascript :: regex to indentify url 
Javascript :: convert json to dataframe python 
Javascript :: how to use hidden in div in angular 
Javascript :: nginx redirect location to port 
Javascript :: node.js f string 
Javascript :: js convert html to text 
Javascript :: javascript get nth element of array 
Javascript :: convert data into json format in javascript 
Javascript :: how to split two digit number in javascript 
Javascript :: javascript delete second last element of array 
Javascript :: how to get file extension in javascript 
Javascript :: checkbox change event javascript 
Javascript :: delta time js 
Javascript :: express return json 
Javascript :: array to string javascript without commas 
Javascript :: unrecognized font family fontawesome react native ios 
Javascript :: how to kill all node processes in windows 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =