Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to generate an index with a too long name (> 127 char) with ensureIndex throw MongoCommandException with confusing error message #156

Closed
y5856 opened this issue Nov 21, 2019 · 1 comment

Comments

@y5856
Copy link

y5856 commented Nov 21, 2019

Using ensureIndex() to create an index the following exception was thrown MongoCommandException with message : Caused by: com.mongodb.MongoCommandException: Command failed with error 27 (IndexNotFound): 'can't find index with key: { ... which is unexpected.

It seems that ensureIndex() calls createIndex() and, if an exception is caught, calls dropIndex() then createIndex() with the same keys.

The first call to createIndex() throws this (as my index name was too long) :
Command failed with error 67 (CannotCreateIndex): 'namespace name generated from index name "<TOO_LONG_FULL_INDEX_NAME>" is too long (127 byte max)' ...

Then dropIndex() tries to drop a non-existing index and throws the IndexNotFound exception.

Propagating the CannotCreateIndex exception would make debugging easier.

@zigzago
Copy link
Member

zigzago commented Nov 21, 2019

True. I fix it.

zigzago added a commit that referenced this issue Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants