How to define delimeter to import mongodb
Asked Answered
Y

2

5

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
Yahiya answered 25/11, 2013 at 8:25 Comment(5)
mongoimport can handle json, csv and tsv. You need to convert this file into csv or tsv format.Pigtail
ok, if we convert to the csv file, how can I separate fields with '|' pipeline characterYahiya
"csv" = comma separated.Pigtail
Can't we use csv file to separate with '|', or it is only able to separate with ','Yahiya
By definition, the "c" in csv stands for "comma".Pigtail
S
12

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.

Sortition answered 25/11, 2013 at 10:1 Comment(0)
V
0

mongodb could actually treat a | seperated record in a .unl, .txt, .csv

Just make sure you do this in the format below. For the specified mentioned extensions use the --type csv:

mongoimport -c <table_name> -d <database_name> --mode upsert --file <filename> --type csv --headerline
Vendor answered 18/9, 2017 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.