解决mongorestore恢复警告don‘t know what to do with subdirectory “xxxx/xxx“, skipping...

解决方法

使用mongodump导出时,每一个集合都会对应到以下两个文件:

  • 集合名.metadata.json
  • 集合名.bson

使用mongorestore时,导入的文件直接指定到.bson后缀的文件,如使用:

./mongorestore -h 192.168.1.150:27017
	--authenticationDatabase admin
	-u mongo_user
	-p mongo_pass
	-d my_data
	/Users/xq/Desktop/mongo_wind_data/wind_data/stock_k_line.bson

这样就可以恢复一个库里的固定的集合

问题解析

通常来讲是可以直接把文件夹传进去的,有时候会成功,但是如果失败,会报一个编码的报错,且在谷歌上是人类未知领域,几乎找不到解决方案,因此只好曲线救国,循环导出的文件夹里的每一个bson文件

这里有一个小脚本:

for bson_file in `ls 恢复数据的文件夹`: # 循环想要恢复数据的那个文件夹,拿到文件名
do
    cd ~/mongodb-database-tools-macos-x86_64-100.6.1/bin # 进入到包含mongorestore的工具包目录
    if [[ "$bson_file" == *".bson"* ]]; then
        ./mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -u user -p password -d cover_data ~/my_data/$bson_file
        # 使用用户名user,密码password,来运行mongorestore,直接恢复具体的 ~/my_data/xxx.bson文件
    fi
done

使用示例:

for bson_file in `ls wind_data`:
do
    cd ~/mongodb-database-tools-macos-x86_64-100.6.1/bin
    if [[ "$bson_file" == *".bson"* ]]; then
        ./mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -u user -p password -d cover_data ~/my_data/$bson_file
    fi
done
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆萌的代Ma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值