kingneil
kingneil

Reputation: 95

MongoDB exception: WiredTigerIndex::insert: key too large to index

I have a MongoDB collection.

I want to change the indexing, to have a dual index, rather than a single.

So I ran:

db.allnews.ensureIndex( { "url": 1, "source": 1 }, { unique: true } )

But then I get the error:

exception: WiredTigerIndex::insert: key too large to index

And the limit is 1024 bytes

So what is the solution...?

(1) Ignore it somehow.. somehow skip these records that are too long, without stopping the entire process..?

--setParameter failIndexKeyTooLong=false

?? Could this do the trick..?

(2) Find the records that are too long, through some sort of query, and shorten them..?

(3) Something else..?

Upvotes: 3

Views: 6556

Answers (1)

kingneil
kingneil

Reputation: 95

OK, I solved my issue.

Run this:

db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )

Then you can create your dual index without it throwing an error

db.getCollection("allnews").ensureIndex( { "url": 1, "source": 1 }, { unique: true } )

Upvotes: 6

Related Questions