我已經將一些PDF,PNG文件上傳到本地mongodb實例。我錯誤地刪除了這些文件,並且無法使用常規恢復選項來恢復它們。但是,它們在我本地的mongodb數據庫中。我如何在計算機上將它們保存爲原始格式?使用Python保存存儲在Mongodb GridFS中的pdf文件
我瞭解以下內容:
import pymongo as pym
import gridfs
def connectToDb():
client = pym.MongoClient('mongodb://localhost:27017/')
db = client.questionbank
collectn = db.questionbank
fs = gridfs.GridFS(db)
return db, collectn, fs
db, collectn, fs = connectToDb()
filelist = list(db.fs.files.find({}, {"_id": 1, "filename": 1}))
fileid = filelist[0]['_id']
fobj = fs.get(fileid)
## I don't know what to do after this. I think I cannot use read since I don't
## want the string. I want to save the pdf file as a pdf file.
任何幫助將不勝感激。提前致謝。