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

MongodbLocaleUbuntu 12.04MongodumpMongorestore

Mongodb Problem Overview


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?

Mongodb Solutions


Solution 1 - Mongodb

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

Solution 2 - Mongodb

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.

Solution 3 - Mongodb

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.

Solution 4 - Mongodb

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.

Solution 5 - Mongodb

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"

Solution 6 - Mongodb

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLuca AnceschiView Question on Stackoverflow
Solution 1 - MongodbkeisarView Answer on Stackoverflow
Solution 2 - MongodbLuca AnceschiView Answer on Stackoverflow
Solution 3 - MongodbjoschView Answer on Stackoverflow
Solution 4 - MongodbAlexView Answer on Stackoverflow
Solution 5 - MongodbSebastien LorberView Answer on Stackoverflow
Solution 6 - MongodbDaniele VrutView Answer on Stackoverflow