pythonlmdb

Count number of records in lmdb databse with python


I open a lmdb database using this code:

    lmdb_env = lmdb.open(source_path, readonly=True)

How can I count the number of records in this database?


Solution

  • I found a simple solution using for loop. Here it is:

    count = 0
    for key, value in lmdb_env.cursor():
            count = count + 1  
    

    However, I think there should be a better way using pre-defined function.