Mongoose delete array element in document and save

后端 未结 6 409
盖世英雄少女心
盖世英雄少女心 2020-11-28 23:53

I have an array in my model document. I would like to delete elements in that array based on a key I provide and then update MongoDB. Is this possible?

Here\'s my

6条回答
  •  有刺的猬
    2020-11-29 00:43

    keywords = [1,2,3,4];
    doc.array.pull(1) //this remove one item from a array
    doc.array.pull(...keywords) // this remove multiple items in a array
    

    if you want to use ... you should call 'use strict'; at the top of your js file; :)

提交回复
热议问题