1

I was looking to pull(remove) values from my data collection based on array index. this is how my collection looks.

"experience" : [ 
        "neeee", 
        "avvvvvvv", 
    ],

I'm looking to remove experience[1]

 var update = {
    $pull: {
      'profile.experience': delet
    }
  };
 this.findByIdAndUpdate(id,update,{ 'new': true},function(err,doc) {
    if (err) { console.log(err);
      callback(err);
    } else if(doc){
      callback(null,doc);
    }

my delet looks like this: [1] i was not able to delete (pull) what may be the reason.

santhosh
  • 1,919
  • 3
  • 21
  • 33
  • try this => var myObj = ...; collection.findOneAndUpdate( {uniqueAttr: myObj.uniqueAttr}, myObj,{upsert: true}, function(...) {...}); – skmahawar Dec 11 '15 at 13:26
  • Possible duplicate of [In mongoDb, how do you remove an array element by its index](http://stackoverflow.com/questions/4588303/in-mongodb-how-do-you-remove-an-array-element-by-its-index) – Philipp Dec 11 '15 at 14:53

0 Answers0