Overwrite : true not working in FindOneAndUpdate in MongoDB

Below is my Schema and API

Schema.js file

const  structure = new mongoose.Schema({
    Name: {
        type:String,
        required:[true,"Please Enter Task"],
    },
    Completed: {
        type:Boolean,
        default:false
    }
})

let work = mongoose.model('tasks',structure)     

module.exports = work

I have imported it in the api file and wrote an api to update records

const work = require("../models/schema.js")

async function updateone(req,res)
{   
    console.log(req.body)
    try {
        let treat = {"First" :"Michael" }
        let newtask =  await 
        work.findOneAndUpdate({_id:req.params.id},treat,{ overwrite: true })   
        res.status(200).json(newtask)
    } 
    catch (error) {
        res.status(500).json({status:"Fail",msg:"Wrong Parameter"})
    }
}

Now , I want that upon updating , only name shall remain and Completed field should not be there. I know that mongoose by default wraps it in $set therefore I used overwrite:true so that my entire document will be replaced.

However , I am seeing that the value Name is replaced but the Completed field is still present. Also I noticed that if I provide a totally new field then nothing changes.
It means if :-

let treat = {"Job" :"Pilot" }
let newtask =  await work.findOneAndUpdate({_id:req.params.id},treat,{ overwrite: true })  

In this case nothing changes , no new field is added at all.What am I doing wrong here ?

Hello @Brijesh_Roy, Welcome to the MongoDB Community Forum :tada:,

First of all, there is no overwrite property in the options of findOneAndUpdate method, you can refer to the mongoose documentation

If you want to replace the document then you can use replaceOne method.

mongoose schema is strict by default, you can’t insert or retrieve except specified properties in the schema.

You can use strict: false property in schema options, refer to the documentation.

const  structure = new mongoose.Schema({
    Name: {
        type:String,
        required:[true,"Please Enter Task"],
    },
    Completed: {
        type:Boolean,
        default:false
    }
},
{ strict: false })

Hello,
Thank you very much for your reply. Actually I came across overwrite proerty in documentation only .
Here it is :- Mongoose documentation

Can you please help me decide.I am unable to implement it.

I am not sure about it but there is an alternate function findOneAndReplace as well, did you tried it?
https://mongoosejs.com/docs/api/model.html#model_Model-findOneAndReplace