mongo数据的导入(mongoimport)和导出(mongoexport)

1、导出数据可以使用命令:  

mongoexport -h dbhost -d dbname -c collectionName -o output  
参数说明:  
-h  数据库地址                           
-d  指明使用的库                       
-c  指明要导出的集合   
-o  指明要导出的文件名   (因为是具体的集合,所以要指定文件名) </span> 

2、导入数据可以使用命令:

mongoimport -h dbhost -d dbname -c collectionname 文件的地址...  
 参数说明:  
  -h  数据库地址  
  -d  指明使用的库  
  -c  指明要导入的集合  
  本地的文件地址...  

3、数据库具体集合的备份与恢复的小案例

#备份test数据库的c3集合  
> mongodump -h localhost:27017 -d test  -c c3  -o d:/beifeng/c4.txt  
> mongodump -h localhost:27017 -d test  -c c3  -o d:/beifeng/c4.doc  
> mongodump -h localhost:27017 -d test  -c c3  -o d:/beifeng/c4.xls  
                   
#test数据库的c3集合的恢复  
> mongorestore -h localhost:27017 -d test  -c c4   d:/beifeng/c4.txt  

  

原文地址:https://www.cnblogs.com/hyh123/p/8520815.html