Click here to Skip to main content
15,502,868 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have searched a lot but couldn't solve this problem.

This is the Schema

const ToDosSchema = mongoose.Schema({
    userId: {
        type: String,
        required: true
    },
    ToDo: [{
        Task: {
            type: String,
            required: true,

        },
        checked: {
            type: Boolean,
            required: true,
        },

    }
    ]
})


What I have tried:

ToDoModel.updateOne(
        {
            userId: userInfo._id,
            ToDo: {
                $elemMatch: {
                    Task: ToDos.text,
                }
            }
        },
        {
            $set:{
                'ToDo.$.Task': "arslan",
                'ToDo.$.checked': true,

            }

        }, 
        {
            new: true,
            useFinedAndModify: false,
        },
        (err, result) => {
            if (err) {
                console.error("Error ", err);
            }
            else {
                console.log("Result ", result);
            };
        })
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900