Skip to content Skip to sidebar Skip to footer

How To Replace Nan With Null From Mongo Shell?

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 mongoimpor

Solution 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

Post a Comment for "How To Replace Nan With Null From Mongo Shell?"