澳门新蒲京娱乐


集成环境下搭建

Mongodb数据迁移步骤澳门新蒲京娱乐:

导出命令

备份:

mongodump -h 127.0.0.1  -d <db_name> -o <file_name>

一、导出工具mongoexport

参数表明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-f:指明要导出那个列
-o:指明到要导出的文本名
-q:指明导出数据的过滤条件

还原:

mongorestore -d <db_name> <file_name>
实例:test库中留存着三个students集结,会集中数据如下:
db.students.find()  
{ "_id" : ObjectId("5031143350f2481577ea81e5"), "classid" : 1, "age" : 20, "name" : "kobe" }  
{ "_id" : ObjectId("5031144a50f2481577ea81e6"), "classid" : 1, "age" : 23, "name" : "nash" }  
{ "_id" : ObjectId("5031145a50f2481577ea81e7"), "classid" : 2, "age" : 18, "name" : "james" }  
{ "_id" : ObjectId("5031146a50f2481577ea81e8"), "classid" : 2, "age" : 19, "name" : "wade" }  
{ "_id" : ObjectId("5031147450f2481577ea81e9"), "classid" : 2, "age" : 19, "name" : "bosh" }  
{ "_id" : ObjectId("5031148650f2481577ea81ea"), "classid" : 2, "age" : 25, "name" : "allen" }  
{ "_id" : ObjectId("5031149b50f2481577ea81eb"), "classid" : 1, "age" : 19, "name" : "howard" }  
{ "_id" : ObjectId("503114a750f2481577ea81ec"), "classid" : 1, "age" : 22, "name" : "paul" }  
{ "_id" : ObjectId("503114cd50f2481577ea81ed"), "classid" : 2, "age" : 24, "name" : "shane" }  

由上能够看到文书档案中设有着一个字段:classid、age、name

  • 一.一向导出数据到文件中

[root@localhost mongodb]# ./bin/mongoexport -d test -c students -o students.dat  
connected to: 127.0.0.1  
exported 9 records  

指令实行完后,开采目录下生成了一个students.dat的文书
翻开该公文音信,具体音讯如下:

[root@localhost mongodb]# cat students.dat   
{ "_id" : { "$oid" : "5031143350f2481577ea81e5" }, "classid" : 1, "age" : 20, "name" : "kobe" }  
{ "_id" : { "$oid" : "5031144a50f2481577ea81e6" }, "classid" : 1, "age" : 23, "name" : "nash" }  
{ "_id" : { "$oid" : "5031145a50f2481577ea81e7" }, "classid" : 2, "age" : 18, "name" : "james" }  
{ "_id" : { "$oid" : "5031146a50f2481577ea81e8" }, "classid" : 2, "age" : 19, "name" : "wade" }  
{ "_id" : { "$oid" : "5031147450f2481577ea81e9" }, "classid" : 2, "age" : 19, "name" : "bosh" }  
{ "_id" : { "$oid" : "5031148650f2481577ea81ea" }, "classid" : 2, "age" : 25, "name" : "allen" }  
{ "_id" : { "$oid" : "5031149b50f2481577ea81eb" }, "classid" : 1, "age" : 19, "name" : "howard" }  
{ "_id" : { "$oid" : "503114a750f2481577ea81ec" }, "classid" : 1, "age" : 22, "name" : "paul" }  
{ "_id" : { "$oid" : "503114cd50f2481577ea81ed" }, "classid" : 2, "age" : 24, "name" : "shane" }  

参数表明:
-d:指明使用的库,本例中为test
-c:指明要导出的聚合,本例中为students
-o:指明要导出的文件名,本例中为students.dat
从上边的结果能够看看,大家在导出数据时未尝体现钦赐导出样式
,暗许导出了JSON格式的数量。假诺大家须求导出CSV格式的数量,则需求动用–csv参数,具体如下所示:

[root@localhost mongodb]# ./bin/mongoexport -d test -c students --csv -f classid,name,age -o students_csv.dat  
connected to: 127.0.0.1  
exported 9 records  
[root@localhost mongodb]# cat students_csv.dat   
classid,name,age  
1.0,"kobe",20.0  
1.0,"nash",23.0  
2.0,"james",18.0  
2.0,"wade",19.0  
2.0,"bosh",19.0  
2.0,"allen",25.0  
1.0,"howard",19.0  
1.0,"paul",22.0  
2.0,"shane",24.0  
[root@localhost mongodb]#   

参数表达:
-csv:指明要导出为csv格式
-f:指明供给导出classid、name、age那三列的数目
由地点结果能够看来,mongoexport成功地将数据依靠csv格式导出到了students_csv.dat文件中。

相关文章

No Comments, Be The First!
近期评论
    功能
    网站地图xml地图