0

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?

0

2 Answers 2

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} )
Sign up to request clarification or add additional context in comments.

2 Comments

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.
unfortunately mongoimport has no option yet to understand that "Null" string from csv need to be interpreted as null ...
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.