Prem
Prem

Reputation: 11

How do we override the default indexing limit in mongoDB?

I have an AWS Cognito JWT of more than 125 characters for which I need to create indexing in MongoDB. But the problem is MongoDB indexing accepts the character of max limit, 125. How can we set the max limit or is there any way to increase the default character limit.

I tried indexing the JWT(around 150 characters) where I have the following error.

  MongoError: WiredTigerIndex::insert: key too large to index, failing  1025 { : "[email protected]", "asdfghjkertyjk......"}

This how I created schema index.

schemaName.index({ email: 1, token: 1 });

Upvotes: 0

Views: 203

Answers (1)

Shahar Hadas
Shahar Hadas

Reputation: 2827

I would go with a different approach, as indexing a large text/string field is not always the best option.

Use SHA1 or MD5 to generate a unique checksum of the JWT string (which will give you a constant string length) and save that field. Index and search by that field

Another option is to decode the JWT token to JSON and store it as an embedded document - and then you can index the document (but it's risky option IMHO)

Upvotes: 1

Related Questions