MongoDB mongorestore failure: locale::facet::_S_create_c_locale name not valid
Asked Answered
M

6

103

I created a dump with mongodump on computer A (ubuntu 12.04 server). I moved it to computer B (ubuntu 12.04 server) and typed:

mongorestore -db db_name --drop db_dump_path

It failed and it reported:

connected to: 127.0.0.1
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Aborted

I've successfully accomplished this operation before and this strange behavior has never occurred. What do I need to do to fix this?

Melissamelisse answered 30/9, 2013 at 17:56 Comment(0)
M
52

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.

Melissamelisse answered 1/10, 2013 at 10:51 Comment(4)
this basically helped me. but also had to edit /etc/locale.gen and enable the needed locales (on arch linux)Tyrannosaur
This solved the problem for me too. This is on Lubuntu 12.04 x86.Overpass
But why is this happening, is there any specific reasons that mongodump / restore depends on locale languages ?Grimalkin
@MarianTheisen That was the culprit for me as well, I'm on a fresh Arch install and got the error while trying to run rescuetime. Fixing /etc/locale.gen and running locale-gen was all that was required.Wheresoever
M
259

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...

Marsha answered 11/11, 2013 at 11:25 Comment(4)
This works fine in a terminal session, but if you look for a permanent solution you'd rather check https://mcmap.net/q/209379/-mongodb-mongorestore-failure-locale-facet-_s_create_c_locale-name-not-validOverarm
Thanks @SebastienLorber, in my case I added this line to my ~/.profile or ~/.bashrc and it worked permanentlyMarsha
Hmmm, came here just prior to reading that setting LC_ALL is strongly discouraged: wiki.debian.org/LocaleLucchesi
Damn, but this LC_ALL setting solved the problem right and there, instantly and without requiring root privileges. Nevermind, hopefully there won't be any darkness bugs haunting me later.Lucchesi
M
52

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.

Melissamelisse answered 1/10, 2013 at 10:51 Comment(4)
this basically helped me. but also had to edit /etc/locale.gen and enable the needed locales (on arch linux)Tyrannosaur
This solved the problem for me too. This is on Lubuntu 12.04 x86.Overpass
But why is this happening, is there any specific reasons that mongodump / restore depends on locale languages ?Grimalkin
@MarianTheisen That was the culprit for me as well, I'm on a fresh Arch install and got the error while trying to run rescuetime. Fixing /etc/locale.gen and running locale-gen was all that was required.Wheresoever
B
17

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.

Beaver answered 27/1, 2016 at 13:26 Comment(0)
I
10

If you are using a Mac OSX and SSH this might be issued by wrong LC_CTYPE.

$ locale 
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Unset the wrong var.

$ unset LC_CTYPE 

Check whether locale is working fine.

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Now mongo also should do fine.

Inhabited answered 16/6, 2015 at 17:6 Comment(2)
Works like a charm. Very native and fast.Reprint
@user1219736 You saved my day :PSickert
O
10

To make the fix permanent you can edit one of those files:

  • sudo vim /etc/default/locale
  • sudo vim /etc/environment

And add the line LC_ALL="en_US.UTF-8"

Overarm answered 24/9, 2015 at 13:12 Comment(1)
this worked for me (centos, AWS c4.8xlarge, helped with vivado starting fix)Arezzo
D
9

Got same problem on debian 7 without locale-gen (command not found) installed.

I solved this way:

su
apt-get install locales
dpkg-reconfigure locales # select locales you want!

Now mongodb should start.

Source

Damage answered 13/12, 2013 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.