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
?
Asked
Active
Viewed 415 times
0

Avani Khabiya
- 1,207
- 2
- 15
- 34
2 Answers
1
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} )

R2D2
- 9,410
- 2
- 12
- 28
-
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. – Avani Khabiya Dec 30 '20 at 12:26
-
unfortunately mongoimport has no option yet to understand that "Null" string from csv need to be interpreted as null ... – R2D2 Dec 30 '20 at 12:57
1
I couldn't find a solution to import the data with NULL
values using CSV and have them stored with datatype NULL
in Mongodb. Then I imported the same data using JSON and it worked!! Importing data using JSON makes it to interpret NULL as NULL datatype, not as string.

Avani Khabiya
- 1,207
- 2
- 15
- 34