MongoDB备份与恢复

备份恢复工具介绍

mongodb有两款备份恢复工具,分别是

  • mongoexport/mongoimport
    导入/导出的是JSON格式 或 CSV格式
  • mongodump/mongorestore
    导入/导出的是BSON格式

两种格式区别

  • JSON可读性强但体积较大,BSON则是二进制文件,体积小但对人类几乎没有可读性。
    json的优劣:
    JSON虽然具有较好的跨版本通用性,但其只保留了数据部分,不保留索引,账户等其他基础信息。使用时应该注意。

  • bson的优劣
    BSON格式可能会随mongodb版本不同而有所不同,所以不同版本之间用mongodump/mongorestore可能不会成功
    当无法使用BSON进行跨版本的数据迁移的时候,可使用JSON格式

JSON格式工具使用

导出工具mongoexport

Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。
可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。

mongoexport参数说明

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


# 单表备份至json格式
mongoexport -uroot -proot123 --port 27017 \
  --authenticationDatabase admin -d noah -c log \
  -o /tmp/log.json


# 单表备份至csv格式
# 如果需要导出CSV格式的数据,则需要使用----type=csv参数:需要制定导出的列名

mongoexport -uroot -proot123 --port 27017 \
  --authenticationDatabase admin -d noah -c log \
  --type=csv -f uid,name,age,date  \
  -o /tmp/log.csv

导入工具mongoimport

Mongodb中的mongoimport工具可以把一个特定格式文件中的内容导入到指定的collection中。
该工具可以导入JSON格式数据,也可以导入CSV格式数据。具体使用如下所示:

mongoimport 参数说明

 mongoimport --help
# 参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-f:指明要导入那些列
-j, --numInsertionWorkers=<number>  (defaults to 1)  //并行备份

# 恢复json格式表数据到log1

mongoimport -uroot -proot123 --port 27017 \
  --authenticationDatabase admin -d noah \
  -c log1 /tmp/log.json

# 恢复csv格式的文件到log2
# 如果要导入CSV格式文件中的内容,则需要通过--type参数指定导入格式,具体如下所示:

# csv格式的文件头行,有列名字
mongoimport   -uroot -proot123 --port 27017 \
  --authenticationDatabase admin   -d noah \
  -c log2 --type=csv --headerline --file  /tmp/log.csv
# --headerline:指明第一行是列名,不需要导入。

# csv格式的文件头行,没有列名字
mongoimport   -uroot -proot123 --port 27017 \
  --authenticationDatabase admin   -d oldboy \
  -c log3 --type=csv -f id,name,age,date --file  /tmp/log1.csv

异构平台迁移案例

mysql -----> mongodb
world数据库下city表进行导出,导入到mongodb

# mysql开启安全路径
# 添加以下配置
vim /etc/my.cnf
secure-file-priv=/tmp

# 重启数据库生效
/etc/init.d/mysqld restart


# 导出mysql的city表数据

# 导入模板数据
source /root/world.sql

# 导出city表数据
select * from world.city into outfile '/tmp/city1.csv' fields terminated by ',';

# 导出列名,添加至导出文件
mysql> desc world.city
  ID          | int(11)  | NO   | PRI | NULL    | auto_increment |
| Name        | char(35) | NO   |     |         |                |
| CountryCode | char(3)  | NO   | MUL |         |                |
| District    | char(20) | NO   |     |         |                |
| Population

mysql> 

# 添加第一行列名信息
vim /tmp/city.csv
mysql> select group_concat(column_name) from information_schema.columns where table_schema='world' and table_name='city';
+-----------------------------------------+
| group_concat(column_name)               |
+-----------------------------------------+
| ID,Name,CountryCode,District,Population |
+-----------------------------------------+
1 row in set (0.00 sec)

mysql>
# 导出文件第一行插入字段名称
sed -i '1 i\ID,Name,CountryCode,District,Population' ./city.csv

# 查看插入结果
head -1 ./city.csv
ID,Name,CountryCode,District,Population

# 在mongodb中导入备份
mongoimport -uroot -proot123 --authenticationDatabase admin -d simon -c city --type=csv --headerline /tmp/city.csv


# 没有头行字段的话,就用-f参数指定字段名称
# 删除头行文字
sed -i '1 d' /tmp/city.csv

# 查看第一行
head -1 ./city.csv

# 导入,用-f参数指定字段名称
mongoimport -uroot -proot123 --port 27017 \
--authenticationDatabase admin \
-d world -c city \
--type=csv -f ID,Name,CountryCode,District,Population \
--file  /tmp/city1.csv

# 登陆MongoDB查询
use world
db.city.find({CountryCode:"CHN"});


world共100张表,全部迁移到mongodb

select table_name ,group_concat(column_name) from columns where table_schema='world' group by table_name;

select * from world.city into outfile '/tmp/world_city.csv' fields terminated by ',';

select concat("select * from ",table_schema,".",table_name ," into outfile '/tmp/",table_schema,"_",table_name,".csv' fields terminated by ',';")
from information_schema.tables where table_schema ='world';

导入:
提示,使用infomation_schema.columns + information_schema.tables

mysql导出csv:
select * from test_info   
into outfile '/tmp/test.csv'   
fields terminated by ','    ------字段间以,号分隔
optionally enclosed by '"'   ------字段用"号括起
escaped by '"'           ------字段中使用的转义符为"
lines terminated by '\r\n';  ------行以\r\n结束

mysql导入csv:
load data infile '/tmp/test.csv'   
into table test_info    
fields terminated by ','  
optionally enclosed by '"' 
escaped by '"'   
lines terminated by '\r\n';

BSON格式工具

mongodump和mongorestore

介绍

mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档写入磁盘。
但是存在的问题时使用mongodump产生的备份不一定是数据库的实时快照,如果我们在备份时对数据库进行了写入操作,
则备份出来的文件可能不完全和Mongodb实时数据相等。另外在备份时可能会对其它客户端性能产生不利的影响。

全量备份

备份可在RS副本集内任一节点执行,最好在从库或者Hidden节点

PS:mongodump备份时不需要锁库,可以通过--oplog参数将备份时段的变更记录以日志形式一起备份出来(单实例不支持oplog)

mongodump全量备份会转储admin库下的users和version,所有的用户库和备份时段内的oplog,

转储格式为bson格式的数据文件和json格式的元数据文件

增量备份(oplog日志备份)

只有副本集可以增量备份,单实例没有oplog无法增备
根据全量备份时段备份的的oplog,获取全量备份完成的时间戳

bsondump oplog.bson

可以得出时间戳为(1593309601,1),后期可以通过脚本解析json直接获取

这里说明一下:

MongoDB中的时间戳为(timestamp,i)的形式,其中timestamp为十位时间戳,精确到秒,i表示累增序数,记录着该时间戳内有多少并发操作。
# 基于时间戳的增量备份
mongodump -h localhost --port 27017 \
-u admin -p 123456 \
--authenticationDatabase admin \
-d local -c oplog.rs \
--query '{ts:{$gt:Timestamp(1593309601,1)}}' \
-o /var/lib/mongobak/mongodump_oplog_`date +%Y-%m-%d_%H:%M:%S`

全量恢复

mongorestore恢复时,需要服务开启且停止业务写入,防止数据恢复时写入导致数据错乱

同机(副本集)全量恢复
同副本集的恢复,需要指定主库ip,在primary主库上做恢复,通过oplog同步给从库

mongorestore -h 192.168.73.120 --port 27018 \
-u admin -p 123456 \
--authenticationDatabase admin \
--oplogReplay --dir /var/lib/mongobak/mongodump_2020-06-28

PS:mongorestore只针对insert做恢复,不会恢复update。对于同一个_id的文档,mongorestore会认定为重复并跳过。
可以使用--drop,在import前先删除collection

mongodump用法如下

$ mongodump --help
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件
-j, --numParallelCollections=  number of collections to dump in parallel (4 by default)
--oplog  备份的同时备份oplog

创建备份用户

# 选择认证库
use admin

# 创建备份用户
db.createUser(
{
    user: "backup",
    pwd: "backup",
    roles: [ 
    	{ 
    	role: "backup", 	//拥有备份权限
    	db: "admin" 		//认证库
    	},
        { 
    	role: "restore", 	//拥有恢复权限
    	db: "admin" 		//认证库
    	}
    ]
}
)

# 验证用户
db.auth('backup','backup')

use admin
db.createUser(
{
    user: "backup",
    pwd: "backup",
    roles: [ 
    	        {
    	role: "read",
    	db: "local"
    	},{ 
    	role: "backup",
    	db: "admin"
    	},
        {
    	role: "restore",
    	db: "admin"
    	}
    ]
}
)

# 创建恢复用户
db.createUser(
{
    user: "restore",
    pwd: "restore",
    roles: [ { role: "restore", db: "admin" } ]
}
)
# 验证用户
db.auth('restore','restore')

mongodump和mongorestore基本使用

全库备份

mkdir -p /mongodb/backup/full
mongodump  -uroot -proot123 --port 27017 --authenticationDatabase admin -o /mongodb/backup/full

[mongod@mysql-node01 mongodb]$ mongodump -uroot -pw --authenticationDatabase admin -o /mongodb/backup/full/
2020-10-25T10:18:59.040+0800	writing admin.system.users to 
2020-10-25T10:18:59.041+0800	done dumping admin.system.users (1 document)
2020-10-25T10:18:59.041+0800	writing admin.system.version to 
2020-10-25T10:18:59.041+0800	done dumping admin.system.version (2 documents)
2020-10-25T10:18:59.041+0800	writing simon.log3 to 
2020-10-25T10:18:59.041+0800	writing simon.log to 
2020-10-25T10:18:59.041+0800	writing simon.log1 to 
2020-10-25T10:18:59.041+0800	writing simon.log2 to 
2020-10-25T10:18:59.071+0800	done dumping simon.log3 (10000 documents)
2020-10-25T10:18:59.071+0800	writing simon.city to 
2020-10-25T10:18:59.072+0800	done dumping simon.log (10000 documents)
2020-10-25T10:18:59.072+0800	writing simon.city2 to 
2020-10-25T10:18:59.089+0800	done dumping simon.city (4079 documents)
2020-10-25T10:18:59.089+0800	writing simon.test to 
2020-10-25T10:18:59.092+0800	done dumping simon.log2 (10000 documents)
2020-10-25T10:18:59.092+0800	done dumping simon.log1 (10000 documents)
2020-10-25T10:18:59.093+0800	done dumping simon.test (1 document)
2020-10-25T10:18:59.095+0800	done dumping simon.city2 (4079 documents)
[mongod@mysql-node01 mongodb]$
[mongod@mysql-node01 mongodb]$ cd !$
cd /mongodb/backup/full/
[mongod@mysql-node01 full]$ ls
admin  simon
[mongod@mysql-node01 full]$ ls simon/
city2.bson           log1.bson           log3.bson           test.bson
city2.metadata.json  log1.metadata.json  log3.metadata.json  test.metadata.json
city.bson            log2.bson           log.bson
city.metadata.json   log2.metadata.json  log.metadata.json
[mongod@mysql-node01 full]$ 

备份simon库

mkdir -p /mongodb/backup/simon
$ mongodump   -uroot -proot123 --port 27017 --authenticationDatabase admin -d simon -o /mongodb/backup/simon

[mongod@mysql-node01 full]$ mongodump -uroot -pw --authenticationDatabase admin -d simon -o /mongodb/backup/simon/
2020-10-25T10:21:22.039+0800	writing simon.log3 to 
2020-10-25T10:21:22.039+0800	writing simon.log to 
2020-10-25T10:21:22.039+0800	writing simon.log1 to 
2020-10-25T10:21:22.039+0800	writing simon.log2 to 
2020-10-25T10:21:22.059+0800	done dumping simon.log3 (10000 documents)
2020-10-25T10:21:22.059+0800	writing simon.city to 
2020-10-25T10:21:22.065+0800	done dumping simon.log (10000 documents)
2020-10-25T10:21:22.065+0800	writing simon.city2 to 
2020-10-25T10:21:22.072+0800	done dumping simon.city (4079 documents)
2020-10-25T10:21:22.072+0800	writing simon.test to 
2020-10-25T10:21:22.073+0800	done dumping simon.city2 (4079 documents)
2020-10-25T10:21:22.074+0800	done dumping simon.test (1 document)
2020-10-25T10:21:22.090+0800	done dumping simon.log1 (10000 documents)
2020-10-25T10:21:22.093+0800	done dumping simon.log2 (10000 documents)
[mongod@mysql-node01 full]$ 
[mongod@mysql-node01 full]$ 
[mongod@mysql-node01 full]$ 
[mongod@mysql-node01 full]$ cd /mongodb/backup/simon/
[mongod@mysql-node01 simon]$ ls
simon
[mongod@mysql-node01 simon]$ ls simon/
city2.bson           log1.bson           log3.bson           test.bson
city2.metadata.json  log1.metadata.json  log3.metadata.json  test.metadata.json
city.bson            log2.bson           log.bson
city.metadata.json   log2.metadata.json  log.metadata.json
[mongod@mysql-node01 simon]$

备份simon库下的log集合

$ mongodump -uroot -proot123 --port 27017 --authenticationDatabase admin -d simon -c log -o /mongodb/backup/simon

[mongod@mysql-node01 simon]$ mongodump -uroot -pw --authenticationDatabase admin -d simon -c log3 -o /mongodb/backup/simon/
2020-10-25T10:22:47.637+0800	writing simon.log3 to 
2020-10-25T10:22:47.651+0800	done dumping simon.log3 (10000 documents)
[mongod@mysql-node01 simon]$

压缩备份

$ mongodump   -uroot -proot123 --port 27017 --authenticationDatabase admin -d simon -o /mongodb/backup/ --gzip
mongodump   -uroot -proot123 --port 27017 --authenticationDatabase admin -o /mongodb/backup/ --gzip
$ mongodump   -uroot -proot123 --port 27017 --authenticationDatabase admin -d app -c vast -o /mongodb/backup/ --gzip


[mongod@mysql-node01 simon]$ mkdir -p /mongodb/backup/full-gzip
[mongod@mysql-node01 simon]$ mongodump -uroot -pw --authenticationDatabase admin -o /mongodb/backup/full-gzip/ --gzip
2020-10-25T10:27:49.023+0800	writing admin.system.users to 
2020-10-25T10:27:49.024+0800	done dumping admin.system.users (1 document)
2020-10-25T10:27:49.024+0800	writing admin.system.version to 
2020-10-25T10:27:49.024+0800	done dumping admin.system.version (2 documents)
2020-10-25T10:27:49.024+0800	writing simon.log3 to 
2020-10-25T10:27:49.024+0800	writing simon.log to 
2020-10-25T10:27:49.024+0800	writing simon.log1 to 
2020-10-25T10:27:49.025+0800	writing simon.log2 to 
2020-10-25T10:27:49.060+0800	done dumping simon.log (10000 documents)
2020-10-25T10:27:49.060+0800	writing simon.city to 
2020-10-25T10:27:49.067+0800	done dumping simon.log3 (10000 documents)
2020-10-25T10:27:49.067+0800	writing simon.city2 to 
2020-10-25T10:27:49.086+0800	done dumping simon.city (4079 documents)
2020-10-25T10:27:49.086+0800	writing simon.test to 
2020-10-25T10:27:49.094+0800	done dumping simon.log2 (10000 documents)
2020-10-25T10:27:49.107+0800	done dumping simon.log1 (10000 documents)
2020-10-25T10:27:49.108+0800	done dumping simon.test (1 document)
2020-10-25T10:27:49.111+0800	done dumping simon.city2 (4079 documents)
[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ du -sh /mongodb/backup/full
4.3M	/mongodb/backup/full
[mongod@mysql-node01 simon]$ du -sh /mongodb/backup/full-gzip/
424K	/mongodb/backup/full-gzip/
[mongod@mysql-node01 simon]$
[mongod@mysql-node01 simon]$ cd /mongodb/backup/full-gzip/
[mongod@mysql-node01 simon]$ pwd
/mongodb/backup/full-gzip
[mongod@mysql-node01 simon]$ ls	
[mongod@mysql-node01 full-gzip]$ ls simon/
city2.bson.gz           log1.metadata.json.gz  log.bson.gz
city2.metadata.json.gz  log2.bson.gz           log.metadata.json.gz
city.bson.gz            log2.metadata.json.gz  test.bson.gz
city.metadata.json.gz   log3.bson.gz           test.metadata.json.gz
log1.bson.gz            log3.metadata.json.gz
[mongod@mysql-node01 full-gzip]$

从全备中恢复指定的库

恢复simon库到 simon_gzip

$ mongorestore -uroot -pw --authenticationDatabase admin -d simon_gzip /mongodb/backup/full-gzip/simon --gzip


[mongod@mysql-node01 simon]$ mongorestore -uroot -pw --authenticationDatabase admin -d simon_gzip /mongodb/backup/full-gzip/simon --gzip
2020-10-25T10:34:28.034+0800	the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2020-10-25T10:34:28.034+0800	building a list of collections to restore from /mongodb/backup/full-gzip/simon dir
2020-10-25T10:34:28.034+0800	reading metadata for simon_gzip.city from /mongodb/backup/full-gzip/simon/city.metadata.json.gz
2020-10-25T10:34:28.046+0800	reading metadata for simon_gzip.city2 from /mongodb/backup/full-gzip/simon/city2.metadata.json.gz
2020-10-25T10:34:28.046+0800	reading metadata for simon_gzip.log2 from /mongodb/backup/full-gzip/simon/log2.metadata.json.gz
2020-10-25T10:34:28.046+0800	reading metadata for simon_gzip.log3 from /mongodb/backup/full-gzip/simon/log3.metadata.json.gz
2020-10-25T10:34:28.046+0800	restoring simon_gzip.city from /mongodb/backup/full-gzip/simon/city.bson.gz
2020-10-25T10:34:28.064+0800	restoring simon_gzip.log2 from /mongodb/backup/full-gzip/simon/log2.bson.gz
2020-10-25T10:34:28.070+0800	restoring simon_gzip.city2 from /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:34:28.087+0800	restoring simon_gzip.log3 from /mongodb/backup/full-gzip/simon/log3.bson.gz
2020-10-25T10:34:28.104+0800	no indexes to restore
2020-10-25T10:34:28.104+0800	finished restoring simon_gzip.city2 (4079 documents)
2020-10-25T10:34:28.104+0800	reading metadata for simon_gzip.log1 from /mongodb/backup/full-gzip/simon/log1.metadata.json.gz
2020-10-25T10:34:28.122+0800	restoring simon_gzip.log1 from /mongodb/backup/full-gzip/simon/log1.bson.gz
2020-10-25T10:34:28.123+0800	no indexes to restore
2020-10-25T10:34:28.123+0800	finished restoring simon_gzip.city (4079 documents)
2020-10-25T10:34:28.123+0800	reading metadata for simon_gzip.log from /mongodb/backup/full-gzip/simon/log.metadata.json.gz
2020-10-25T10:34:28.135+0800	restoring simon_gzip.log from /mongodb/backup/full-gzip/simon/log.bson.gz
2020-10-25T10:34:28.164+0800	no indexes to restore
2020-10-25T10:34:28.164+0800	finished restoring simon_gzip.log2 (10000 documents)
2020-10-25T10:34:28.164+0800	reading metadata for simon_gzip.test from /mongodb/backup/full-gzip/simon/test.metadata.json.gz
2020-10-25T10:34:28.167+0800	no indexes to restore
2020-10-25T10:34:28.167+0800	finished restoring simon_gzip.log3 (10000 documents)
2020-10-25T10:34:28.184+0800	restoring simon_gzip.test from /mongodb/backup/full-gzip/simon/test.bson.gz
2020-10-25T10:34:28.201+0800	no indexes to restore
2020-10-25T10:34:28.201+0800	finished restoring simon_gzip.test (1 document)
2020-10-25T10:34:28.219+0800	no indexes to restore
2020-10-25T10:34:28.219+0800	finished restoring simon_gzip.log1 (10000 documents)
2020-10-25T10:34:28.219+0800	no indexes to restore
2020-10-25T10:34:28.219+0800	finished restoring simon_gzip.log (10000 documents)
2020-10-25T10:34:28.219+0800	done
[mongod@mysql-node01 simon]$ 
    
    
[mongod@mysql-node01 simon]$ mongo -uroot -p
MongoDB shell version v3.6.20
Enter password: 
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("013a134e-1322-4900-8466-62591614e91d") }
MongoDB server version: 3.6.20 
> 
> show dbs
admin       0.000GB
config      0.000GB
local       0.000GB
simon       0.002GB
simon_gzip  0.000GB
> use simon_gzip
switched to db simon_gzip
> show tables
city
city2
log
log1
log2
log3
test
>
> db.city2.count( { "CountryCode" : "CHN" } )
363
> 

从全备中恢复指定的集合/表

恢复simon库下的city2集合

# 恢复指定的集合,需要指定具体的集合文件

mongorestore -uroot -pw --authenticationDatabase admin -d world -c t1 --gzip /mongodb/backup/full-gzip/simon/city2.bson.gz


[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ 
[mongod@mysql-node01 simon]$ mongorestore -uroot -pw --authenticationDatabase admin -d world -c t1 --gzip /mongodb/backup/full-gzip/simon/city2.bson.gz 
2020-10-25T10:44:38.259+0800	checking for collection data in /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:44:38.259+0800	reading metadata for world.t1 from /mongodb/backup/full-gzip/simon/city2.metadata.json.gz
2020-10-25T10:44:38.266+0800	restoring world.t1 from /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:44:38.330+0800	no indexes to restore
2020-10-25T10:44:38.330+0800	finished restoring world.t1 (4079 documents)
2020-10-25T10:44:38.330+0800	done
[mongod@mysql-node01 simon]$
[mongod@mysql-node01 simon]$ mongo -uroot -p
MongoDB shell version v3.6.20
Enter password: 
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("873b4e0b-d53a-479c-8aba-4fac57b2d1c2") }
MongoDB server version: 3.6.20
> 
> use world
switched to db world
> db.t1.count()
4079
> 
> db.t1.count( { "CountryCode" : "CHN" } )
363
> 

drop表示恢复的时候把之前的集合drop掉(危险)

# Drop 会把原来的集合删除,然后再创建新的集合

$ mongorestore -uroot -pw --authenticationDatabase admin -d world -c city2 --drop --gzip /mongodb/backup/full-gzip/simon/city2.bson.gz

[mongod@mysql-node01 simon]$ mongorestore -uroot -pw --authenticationDatabase admin -d world -c city2 --drop --gzip /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:50:57.074+0800	checking for collection data in /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:50:57.075+0800	reading metadata for world.city2 from /mongodb/backup/full-gzip/simon/city2.metadata.json.gz
2020-10-25T10:50:57.083+0800	restoring world.city2 from /mongodb/backup/full-gzip/simon/city2.bson.gz
2020-10-25T10:50:57.145+0800	no indexes to restore
2020-10-25T10:50:57.145+0800	finished restoring world.city2 (4079 documents)
2020-10-25T10:50:57.145+0800	done
[mongod@mysql-node01 simon]$
[mongod@mysql-node01 simon]$ mongo -uroot -p
MongoDB shell version v3.6.20
Enter password: 
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("636470f7-c0a7-4cc8-a358-933e98d08109") }
MongoDB server version: 3.6.20
> use world
switched to db world
> show tables
city2
t1
> db.city2.count( { CountryCode : 'CHN' } )
363
> 
posted @ 2022-05-19 23:51  oldSimon  阅读(569)  评论(0编辑  收藏  举报