Remove all fields that are null

前端 未结 5 481
-上瘾入骨i
-上瘾入骨i 2021-01-02 11:03

How can I remove all fields that are null from all documents of a given collection?


I have a collection of documents such as:

{
           


        
5条回答
  •  温柔的废话
    2021-01-02 11:47

    You can use the mongo updateMany functionality, but you must do this by specifying the parameter you are going to update, such as the year parameter:

    db.collection.updateMany({year: null}, { $unset : { year : 1 }})
    

提交回复
热议问题