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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With