I tried uploading data into Mongodb using CSV from Mongodb Compass. In the CSV, some of the fields have Null values stored in them. But, after uploading those fields in Mongo, documents have "Null" stored as String. Is there a way to store Null fields from CSV with the type Null?
Add a comment
|
2 Answers
You can correct easily later:
db.contacts.update({a:"Null"}, {$set: {a: null}},{multi:true} )
or you can remove those fields from the document:
db.contacts.update({a:"Null"}, {$unset: {a:1}},{multi:true} )
2 Comments
Avani Khabiya
I wanted a solution at the time of insertion itself. There are thousands of documents (which will grow later on), don't want to update using query. Though, if it's the only solution will proceed with this.
R2D2
unfortunately mongoimport has no option yet to understand that "Null" string from csv need to be interpreted as null ...