将csv导入MongoDB。

csv-2-mongo的Python项目详细描述


csv-2-mongo

PyPi releaseDownloads

使用python将csv导入mongodb。

安装

$ pip install csv-2-mongo

用法

Usage: csv_2_mongo.py [OPTIONS] FILE

  Import a csv FILE to MongoDB

Options:
  -h, --help             Show this message and exit.
  -v, --version          Show the version and exit.
  -d, --database name    Database name.  [default: test]
  -c, --collection name  Collection name.  [default: test]
  -H, --host host        Host name.  [default: 0.0.0.0]
  -p, --port port        Port number.  [default: 27017]
  -t, --timeout sec      Connection timeout (seconds).  [default: 5]
  -f, --force            Overwrite collection if exists.
  -y, --yes              Automatic yes to prompts.

Note: CSV headers are required to correctly correlate MongoDB fields to CSV fields.

示例

mammals.csv导入animals数据库中的mammals集合:

$ csv-2-mongo -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!
<> > {{CD3}}集合中的{^ }集合,如果存在“< /强>:

”,则覆盖该集合

Note: the -f, --force flag will overwrite the collection without a prompt. If the flag is omitted, csv-2-mongo will prompt you before operations with potential data loss.

$ csv-2-mongo -f -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!

mammals.csv导入mammals集合,该集合位于hostmongo.travismclarke.com上运行的port27111

$ csv-2-mongo -d animals -c mammals -H mongo.travismclarke.com -p 27111 ./mammals.csv
....................................
Connecting to mongo.travismclarke.com:27111
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!

要跳过提示(例如Import data.csv to ...),例如通过脚本运行,可以传递-y--yes标志来强制yes响应确认提示:

Note: this will not suppress the overwrite prompt which still requires the -f, --force flag.

$ csv-2-mongo -y -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import complete!

许可证

麻省理工学院Travis Clarke

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何强制用户在允许访问活动之前处理对话框?我的许可证代码怎么了?   java ArraysList作为JSON   mysql如何在java中创建包含多个可选where子句的搜索语句?   java如何让Apache Camel在“直接”路径的末尾删除文件?   使用socket在两个Androids之间进行java实时数据传输。IO(websocket)和4G   如何在java中实现两个CORBA服务器之间的通信   会话树xml表示为java对象   java Skype4Java编号swtwin323325   java RecyclerView getAdapterPosition()不工作:第一次单击返回正确位置,第二次单击返回1   java在$TOMCAT/conf/context上为JNDI设置资源。xml   java为什么第二个矩形冲突在第一个矩形冲突时不起作用?   JScrollPane上的java JTextArea未出现在JPanel上   java如何将实现的PriorityQueue打印为字符串?   jpa使用Jersey更新用户角色RESTJava(JAXRS)