Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I want to update an array value but I am not sure about the proper method to do it, so for I tried the following method but didn’t work for me.

My model, The children field in my model

childrens: { 

type: Array, 

default: '' 

}

My query,

Employeehierarchy.update({ _id: employeeparent._id} ,{ $set: {"$push": { "childrens": employee._id }} }) .exec(function (err, managerparent) {});

Can anyone please provide me with help. Thanks.

1 Answer

0 votes
by (106k points)

If you want to update an array value in Mongoose you can use the below-mentioned code:-

Employeehierarchy.findOneAndUpdate( 

{ _id:employeeparent._id }, 

{ $set: { "childrens": employee._id }} 

)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...