This script will generate a binary objects (e.g. files) containing random bytes and store those large files in MongoDB using python
The below python packages need to be installed.
pip install --user pymongo
pip install --user gridfs
pip install --user os
modify the script with the preferred parameters/variables
client = MongoClient("mongodb://localhost:27017/", username='', password='') --> specify the host,port,username and password of mongodb
database = '' --> The name of the Database. test_database is the default value.
for numFile in range(10): --> How many files to be uploaded. 10 files is the default value.
newfile.write (os.urandom(500000000)) --> generate 500MB random content. file 1Mb is the default value.
./create_store_files_monogodb.py
Connected successfully to Mongodb!
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
New File uploaded with Size 1 MegaBytes
10 files are uploaded successfully
Total dataSize uploaded into DB test_database: 10 MegaBytes```