MongoDB mongorestore failure: locale::facet::_S_create_c_locale name not valid

On my distro "locale-gen" was not installed and it turned out all I had to do is set the LC_ALL environment variable. so the following command fixed it:

export LC_ALL="en_US.UTF-8"

hopefully it will help someone else...


Actually it isn't strictly related to MongoDB. Somehow the language on computer B was not defined correctly. I managed to fix it by typing:

sudo locale-gen en_US en_US.UTF-8
sudo locale-gen it_IT it_IT.UTF-8
sudo locale-gen xx_xx xx_XX.UTF-8 ...
sudo dpkg-reconfigure locales

These commands will generate and configure the needed locales. After those steps mongorestore got back working as usual.


Exporting LC_ALL="en_US.UTF-8" only works if you have the en_US locale installed. If you want to avoid installing the locales package (or its equivalent on distributions other than Debian derivatives), then you can instead use:

export LC_ALL=C.UTF-8

which will not require any extra locale data.