G
G
GuF_20192020-09-07 11:02:49
Python
GuF_2019, 2020-09-07 11:02:49

How to programmatically get away from key too large to index error in pymongo python?

I have a database of 2 million records. When I create an index field (db.coll.create_index(...)), I get an error of this type: key too large to index, failing 1098. Apparently, some name did not fit when building the index. Tell me how programmatically through pymongo or bypass this, or increase the size of accepted keys in the index?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WinPooh32, 2020-09-07
@WinPooh32

The crutch solution to your problem is hashing.
1) Before insertion, hash your keys using a non-critical algorithm.
2) When searching by key, do the same.
With such a campaign, there is a chance of being blown up by collisions. You can reduce the probability by making a composite key.
Obviously the key will require a new field.
And it is better to choose more adequate attributes as a key.
UPD: mongo has indexes on hashes .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question