我尝试测试GridFS,但我无法理解: 我已将文件放入本地gridfs。
$ mongofiles list
connected to: 127.0.0.1
IMGP2224.JPG 1125745
在我的代码中:
from pymongo import MongoClient
import gridfs
...
def index():
db = MongoClient('localhost', 27017).gridfs
files = gridfs.GridFS(db)
image = files.list()
import pdb;pdb.set_trace()
**pdb here gives empty []**
return render_template("index.html", images=image)
我做错了什么?
答案 0 :(得分:2)
如果在使用mongofiles
时未提供数据库名称,则它将使用默认数据库(称为test
)。如果您未指定集合名称,则会使用fs.files
和fs.chunks
。
因此,在Python代码中,您需要使用test
作为数据库名称,而不是gridfs,然后它将找到您的默认fs.files
和fs.chunks
集合。