我有 mongo db 数据库,我在其中创建了 bb_attachments gridfs 对象。所以默认情况下有两个集合如下命名。bb_attachments.files、bb_attachments.chunks
当我在文件集合中使用某些文件名查询 mongo shell 时,我得到如下响应...
> db.bb_attachments.files.find({"filename" : "C1208BSP130.pdf"}).toArray()
[
{
"_id" : "20120817014008229971__C1208BSP130.pdf",
"contentType" : "application/pdf",
"chunkSize" : 262144,
"filename" : "C1208BSP130.pdf",
"length" : 9177,
"uploadDate" : ISODate("2012-08-17T01:40:08.253Z"),
"md5" : "da39afb3968195f3ca5b8a1c25394b67"
}
]
>
但是当我使用 python IDLE 查询它时,它没有给我任何文件 Exists 异常,例如..
>>> bb_attachments.exists({"filename" : "C1208BSP130.pdf"})
False
>>>
和异常像..
>>> bb_attachments.get("20120817014008229971__C1208BSP130.pdf").read()
Traceback (most recent call last):
File "<pyshell#50>", line 1, in <module>
bb_attachments.get("20120817014008229971__C1208BSP130.pdf").read()
File "C:\Python25\Lib\site-packages\gridfs\__init__.py", line 130, in get
return GridOut(self.__collection, file_id)
File "C:\Python25\Lib\site-packages\gridfs\grid_file.py", line 343, in __init__
(files, file_id))
NoFile: no file in gridfs collection Collection(Database(Connection('my host', 27017), u'my db'), u'fs.files') with _id '20120817014008229971__C1208BSP130.pdf'
>>>
谁能详细解释一下。为什么我得到 fs.files 而不是 bb_attachments.files?
NoFile: no file in gridfs collection Collection(Database(Connection('my host', 27017), u'my db'), **u'fs.files'**) with _id '20120817014008229971__C1208BSP130.pdf'