How to define delimeter to import mongodb

≯℡__Kan透↙ 提交于 2019-12-10 09:45:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!