Using Mongoose / MongoDB $addToSet functionality on array of objects

前端 未结 2 1460
清酒与你
清酒与你 2020-12-05 14:33

say I have this array property (\'articles\') on a Mongoose schema:

articles: [ 

 {
  kind: \'bear\',
  hashtag: \'foo\'    
 },

 {
  kind: \'llama\',
  ha         


        
2条回答
  •  攒了一身酷
    2020-12-05 15:34

    // add the comment's id to the commentsList : 
                            // share.comments.commentsList.addToSet(callback._id);
                            share.update(
                                { '$push': {'comments.commentsList':  mongoose.Types.ObjectId(callback._id) } }
                            , function(){
                                console.log('added comment id to the commentsList array of obectIds')
                            })
    

提交回复
热议问题