The example in this article describes how Python saves files on MongoDB locally. Share it with everyone for your reference, the details are as follows:
Documents on MongoDB are operated through GridFS. Python can also connect to the MongoDB database through pymongo and use the gridfs method of the pymongo module to operate documents. The following example saves an excel document stored in GridFS on MongoDB locally.
from pymongo import MongoClient import gridfs client = MongoClient('mongodb://username:pwd@192.168.1.22:27017/send_excel') db = client.js_send_excel fs = gridfs.GridFS(db) files = fs.find() print('总数:', files.count()) for ffle in files: if ffle.filename.find('.xls') > 0: with open(ffle.filename, 'wb') as f1: f1.write(ffle.read())
For more Python methods to save files on MongoDB locally, please pay attention to the PHP Chinese website for related articles!