Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongorestore: ns name too long, max size is 128

My Mongo database has few indexes with a custom name, because there are too many fields in them to generate a name automatically without failing with "ns name too long" error.

When I try to restore this database from a backup using mongorestore – it fails with the this very error ("ns name too long, max size is 128"). It seems like mongorestore tries to generate index names based on their content rather than just restore whatever name was actually used in a database.

The only solution I came up with so far is to use mongorestore with --noIndexRestore and recreate all indexes manually after, but this is clearly a terrible way to go. Is there any better way to solve this?

I am experiencing this problem with MongoDB 2.4.1.

Thanks.

like image 619
rakhim Avatar asked Apr 02 '13 20:04

rakhim


1 Answers

mongorestore uses the same names when recreating an index that existed during the dump. You can see what those names were in .metadata.json file in 2.2 and later, before 2.2 the names were in .system.indexes.bson file (it's in BSON so you can examine it using bsondump command).

One way that I have found that you can get this error is if you are restoring into a differently named database or collection and the new name is longer than the original one was. If you use original database name and collection names, the original index name will be used (custom or default) and it will then be a legal name.

like image 107
Asya Kamsky Avatar answered Oct 14 '22 03:10

Asya Kamsky