假设库里有一张user表,里面有2条记录,我们要将它导出 
  
  
  
    
      常用导出方法 
    
    
  
    
    [root@localhost bin]# ./mongoexport -d my_mongodb -c user -o user.dat 
   
    
connected to: 127.0.0.1
exported 2 records
[root@localhost bin]# cat user.dat
{ "_id" : { "$oid" : "4f81a4a1779282ca68fd8a5a" }, "uid" : 2, "username" : "Jerry", "age" : 100 }
{ "_id" : { "$oid" : "4f844d1847d25a9ce5f120c4" }, "uid" : 1, "username" : "Tom", "age" : 25 }
[root@localhost bin]#
  connected to: 127.0.0.1
exported 2 records
[root@localhost bin]# cat user.dat
{ "_id" : { "$oid" : "4f81a4a1779282ca68fd8a5a" }, "uid" : 2, "username" : "Jerry", "age" : 100 }
{ "_id" : { "$oid" : "4f844d1847d25a9ce5f120c4" }, "uid" : 1, "username" : "Tom", "age" : 25 }
[root@localhost bin]#
参数说明
    
    -d  指明使用的库,  本例中为” my_mongodb” 
  
  
  
    
    -c  指明要导出的表,  本例中为”user” 
  
  
  -o  指明要导出的文件名,  本例中为”user.dat” 
  
  从上面可以看到导出的方式使用的是 JSON的样式
    
      导出CSV格式的文件
    
    
  
    
    [root@localhost bin]# ./mongoexport -d my_mongodb -c user  --csv -f uid,username,age - 
   
    
user_csv.dat
connected to: 127.0.0.1
exported 2 records
[root@localhost bin]# cat user_csv.dat
uid,username,age
2,"Jerry",100
1,"Tom",25
[root@localhost bin]#
  user_csv.dat
connected to: 127.0.0.1
exported 2 records
[root@localhost bin]# cat user_csv.dat
uid,username,age
2,"Jerry",100
1,"Tom",25
[root@localhost bin]#
    
      数据导入 
    
    
  
    
      导入json数据 
    
    
  
    
    [root@localhost bin]# ./mongoimport -d my_mongodb -c user user.dat 
   
    
connected to: 127.0.0.1
imported 2 objects
[root@localhost bin]#
  connected to: 127.0.0.1
imported 2 objects
[root@localhost bin]#
    
      导入CSV数据 
    
  
  
    
    [root@localhost bin]# ./mongoimport -d my_mongodb -c user  --type csv --headerline --file 
   
    
user_csv.dat
connected to: 127.0.0.1
imported 3 objects
[root@localhost bin]#
  user_csv.dat
connected to: 127.0.0.1
imported 3 objects
[root@localhost bin]#
    
    参数说明 
   
    
-type 指明要导入的文件格式
-headerline 批明不导入第一行,因为第一行是列名
-file 指明要导入的文件路径
    
  
  -type 指明要导入的文件格式
-headerline 批明不导入第一行,因为第一行是列名
-file 指明要导入的文件路径

