2

I have mongo db database, in which i created bb_attachments gridfs object. So there is by default two collections named below. bb_attachments.files, bb_attachments.chunks

when I query on mongo shell with some file name in files collection I have a response like below...

> 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"
    }
]
>

But when I query it using python IDLE it gives me no file Exists exceptions like..

>>> bb_attachments.exists({"filename" : "C1208BSP130.pdf"})
False
>>>

and exception like..

>>> 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'
>>>

Can anybody explain this in detail. And why I am getting fs.files in rather than 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'

1 Answer 1

4

It looks like your current bb_attachments GridFS object was created with the default prefix of 'fs'.

Try creating it with the correct prefix:

bb_attachments = GridFS(db, collection="bb_attachments")

Now if you run

bb_attachments.exists({"filename" : "C1208BSP130.pdf"})

it should be able to find the file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.