Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define delimeter to import mongodb

I have a data collection, which is separated by | character. I am going to add the data collection to mongodb. So I need to separate data through | character. how my mongoimport command looks like?

Previously, I'm successfully import csv file through the following command.

$ mongoimport -d mydb -c things --type csv --file locations.csv --headerline
like image 898
Shashika Avatar asked Nov 25 '13 08:11

Shashika


People also ask

What is delimiter to importing data?

Simply put: a delimiter is the character that separates fields in your CSV file. It is what the computer reads as a "separator" of sorts, giving structure to your file.

How do I import into MongoDB?

The simplest way to import a single file into MongoDB is to use the --file option to specify a file. In my opinion, the very best situation is that you have a directory full of JSON files which need to be imported.

Can CSV files have different delimiters?

A CSV file stores data in rows and the values in each row is separated with a separator, also known as a delimiter. Although the file is defined as Comma Separated Values, the delimiter could be anything. The most common delimiters are: a comma (,), a semicolon (;), a tab (\t), a space ( ) and a pipe (|).


1 Answers

mongoimport supports either JSON, CSV (comma separated values) or TSV (tab separated values). The | character is not a valid delimiter for either CSV or TSV, so you will need to change your input files' | to , or a tab, and specify --type accordingly.

like image 174
Derick Avatar answered Nov 04 '22 03:11

Derick