How to replace NaN with null from Mongo shell?

拜拜、爱过 提交于 2021-01-29 06:34:48

问题


I have made a json file using pandas by combining two other pandas dataframes. But after uploading it to server and importing it to a new database's new collection using mongoimport, I have found that all the blank string fields which should be appeared as null are now showing as NaN. How can I convert these NaNs to nulls from mongo shell? Please note that I have to do it from the server, and there is no MongoDBCompass installed there. I have to do everything from console (PuTTy).


回答1:


Alright, I was just an update operation away. I fixed the problem with the following mongo shell update command to replace all NaNs with nulls:

The {multi: true} for replacing all of the matches.

database_name.collection_name.update({"field_name_having_NaN": {$eq: NaN}}, {$set: {"field_name_having_NaN": null}}, {multi: true});

Reference: MongoDB Field Update Operator - $set



来源:https://stackoverflow.com/questions/65879905/how-to-replace-nan-with-null-from-mongo-shell

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