Le I reveal my comment above.
All entries in LMDB are stored in accordance with unique keys, and your database already contains keys for i = 0, 1, 2, ... You need to find unique keys for each i . The easiest way to do this is to find the largest key in the existing database and continue to add to it.
Assuming existing keys are sequential,
max_key = env.stat()["entries"]
Otherwise, a more thorough approach is to repeat all the keys. ( Check it out. )
max_key = 0 for key, value in env.cursor(): max_key = max(max_key, key)
Finally, just replace line 7 of your for loop,
str_id = '{:08}'.format(i)
by
str_id = '{:08}'.format(max_key + 1 + i)
to add to an existing database.
source share