how to remove array filed with value null after unset in mongodb

守給你的承諾、 提交于 2021-02-08 06:44:26

问题


I had unset an array field, in mongo but it's leave the field with valué null,

the question is, how to remove it!

like this image http://i.stack.imgur.com/O2WiV.png


回答1:


You could remove all null elements from the array with the $pull operation.
See docs

Code example:

db.collecton.update({condition: "x"}, {$pull: {state: null}});


来源:https://stackoverflow.com/questions/19445508/how-to-remove-array-filed-with-value-null-after-unset-in-mongodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!