1

I am trying to update the skill endorsements for users, this my user schema

{
 _id:'123456',
 firstName:'xyz',
 skills:[
  {
   title:'HTML',
   endorsement:['12','13','14'] 
  },
  {
   title:'CSS',
   endorsement:[] 
  }
 ]
}

I want to push the id of user in endorsement array after finding that skill by its title, this the query's I'm using but its now working or me

   1) update({_id:user_id,skills:{$elemMatch: {title:'HTML'}}},{ skills:{title:"HTML",$push:{endorsement: id}}}) 

   2) update({_id:user_id,skills:{$elemMatch: {title:'HTML'}}},{ $push: {endorsement: id}})

Here user_id is the skill holder and id is the skill endorser.

Community
  • 1
  • 1

1 Answers1

0

Its been some time since i used mongo so not sure about this but have you tried updating this way?

update({_id:user_id,skills.title:'HTML'}}},{ $push: {skills.$.endorsement: id}})
Nijeesh
  • 848
  • 7
  • 11