0 votes
1 view
in Web Technology by (47.8k 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 (107k points)

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


{ _id:employeeparent._id }, 

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


Welcome to Intellipaat Community. Get your technical queries answered by top developers !