MongoDB, update collection field if new value is not null

前端 未结 8 856
感情败类
感情败类 2020-12-29 13:45

I would update a collection setting the value only if the new values are not null. I have a code like this:

 ...
 var userName = req.body.nome;
 var userSurn         


        
8条回答
  •  被撕碎了的回忆
    2020-12-29 14:10

    You can use lodash like this other question: https://stackoverflow.com/a/33432857/4777292

    _.pickBy({ a: null, b: 1, c: undefined }, _.identity);

    would be

    {b:1}

提交回复
热议问题