xiang8 发表于 2015-7-7 11:17:27

MongoDB 导入CSV

  MongoDB导入和导出
  (1)、mongoexport导出工具
  MongoDB提供了mongoexport工具,可以把一个collection导出成json格式或csv格式的文件。可以指定导出哪些数据项,也可以根据给定的条件导出数据。工具帮助信息如下:
  

# ./mongoexport --helpoptions:
--help produce help message   
-v [ --verbose ] be more verbose (include multiple times for more   
verbosity e.g. -vvvvv)   
-h [ --host ] arg mongo host to connect to ( /s1,s2 for sets)   
--port arg server port. Can also use --host hostname:port   
--ipv6 enable IPv6 support (disabled by default)   
-u [ --username ] arg username   
-p [ --password ] arg password   
--dbpath arg directly access mongod database files in the given   
path, instead of connecting to a mongod server -   
needs to lock the data directory, so cannot be used   
if a mongod is currently accessing the same path   
--directoryperdb if dbpath specified, each db is in a separate   
directory   
-d [ --db ] arg database to use   
-c [ --collection ] arg collection to use (some commands)   
-f [ --fields ] arg comma separated list of field names e.g. -f name,age   
--fieldFile arg file with fields names - 1 per line   
-q [ --query ] arg query filter, as a JSON string   
--csv export to csv instead of json   
-o [ --out ] arg output file; if not specified, stdout is used   
--jsonArray output to a json array rather than one object per   
line   
#
  例: E:\mydrive\Project\HouseDataManageSystem\DB\mongoDB\bin\mongoexport -h "127.0.0.1:16688" -u"username" -p "password" -d "hdms" -c "MS_Updatelog" -f "Up_id,Up_content,Up_Updatetime" -type=csv -file=d:\MS_UpdateLog.csv
  
  如需导入数据,则用mongoimport命令
  
  
页: [1]
查看完整版本: MongoDB 导入CSV