时间:2021-07-01 10:21:17 帮助过:29人阅读
import pymongo; #MongoDB操作模块
import gridfs; #存储桶
client = pymongo.MongoClient("mongodb://localhost:27017") #获得数据库连接
db = client["trs"] #指定数据库表
fs = gridfs.GridFS(db) #获取gridfs对象
fsb = gridfs.GridFSBucket(db)
files = fs.find()
try:
i=1
for file in files:
print("["+str(i)+"]""finename is :" + file.name)
file = fs.find_one({"filename":file.name})
local = open(str(file._id),‘wb+‘)
stream = fsb.download_to_stream(file._id,local)
i=i+1
except Exception as e:
print(str(e))
使用Python将MongoDB的GirdFS的文件导出
标签:python mongodb idf grid file except for int name