1

I have pushed so many same values in a single array of a mongodb document, likewise following document row

//var posts_document = {_id: '54ab8d71f8ab49ac10e64125', comment_ids: ['1','2','3','1','2','1'], is_delete: 0, status: 1};

I'd like to pop only one instance of a '2' comment_id from 'comment_ids' array in mongodb

desired document after pop

//var posts_document = {_id: '54ab8d71f8ab49ac10e64125', comment_ids: ['1','2','3','1','1'], is_delete: 0, status: 1};

now my query for pop a single value

var ids_action = {};
ids_action['comment_ids'] ='2' ; // the value
db.collection('posts').update({_id: new mongo.ObjectID('54ab8d71f8ab49ac10e64125')}, {$pull: ids_action})

when I am trying to pop a value which have multiple instances then all the values have been popped out not only single instance.

//var posts_document = {_id: '54ab8d71f8ab49ac10e64125', comment_ids: ['1','3','1','1'], is_delete: 0, status: 1};

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
Dineshaws
  • 2,065
  • 16
  • 26

0 Answers0