问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/20187723/how-to-define-delimeter-to-import-mongodb