1

I'm trying to update a document with findOneAndUpdate(). However, a document with different id is getting updated.

Code is as below:

async function updateDocument(id){
    const result = await Collection1_class.findOneAndUpdate(id,{
        $set : { author : 'John'}
    }, { new : true});    
    console.log(result);
}
updateDocument('5a6900fff467be65019a9001');

Output is as below:

Connected to database1
{
  tags: [ 'aspnet', 'backend' ],
  _id: 5a68fde3f09ad7646ddec17e,
  date: 2018-01-24T21:42:59.605Z,
  name: 'ASP.NET MVC Course',
  author: 'John',
  isPublished: true,
  price: 15,
  __v: 0
}
nandhini
  • 11
  • 2

0 Answers0