MongoDB dump from 3.2, restore with 3.4, error index safe = null

时间秒杀一切 提交于 2019-11-30 02:57:33

safe=true is not an index specification.

In previous versions of MongoDB, lower than 3.4, extra indexes specifications can be added. Those were used by specific drivers.

In 3.4, mongodb added a validation on indexes specification:

Ensuring that the specified index options are valid. Previous versions ignored invalid options.

That's why you have this error. I am afraid you need to ensure that the index in your 3.2 version does not have invalid index specificaitons, and after that do the mongodump.

As kz_sergey says in his answer, you can mongorestore using --noIndexRestore, that should work fine.

Why do you restore indexes? --noIndexRestore and create them again.

In the spirit of Aymeric's comment, you can use this awk one-liner to replace the "safe" property in your .metadata.json files.

awk -i inplace '{gsub(",\"safe\":null", ""); print}' *.metadata.json

find . -type f -name "*.metadata.json" -exec sed -i 's/,"safe":null//g' {} \;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!