MongoDB 導入CSV


MongoDB導入和導出

(1)、mongoexport導出工具

MongoDB提供了mongoexport工具,可以把一個collection導出成json格式或csv格式的文件。可以指定導出哪些數據項,也可以根據給定的條件導出數據。工具幫助信息如下:

 


  • [root@localhost bin]# ./mongoexport 
    --help  
  • options:  
  • --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   
  • [root@localhost bin]#  
  • 例: 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命令 

     

     


    免責聲明!

    本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



     
    粵ICP備18138465號   © 2018-2025 CODEPRJ.COM