Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-2180

Document that GridFS.get is type-sensitive and usually should be an ObjectId

    XMLWordPrintableJSON

Details

    • Task
    • Status: Backlog
    • Minor - P4
    • Resolution: Unresolved
    • 3.10.1
    • None
    • Docs, GridFS
    • None
    • Linux pop-os 5.0.0-21-generic #22+system76-Ubuntu SMP Tue Jul 16 19:57:52 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    Description

      The bug shows even after running the following simple code:

      from pymongo import MongoClient
      import gridfs
       
      client = MongoClient('mongodb://localhost:27017/')
      db = client.my_app
      file_system = gridfs.GridFS(db)
       
      _id = file_system.put(b"hello world")
      print(_id)
      print(str(_id))
      print(file_system.get(_id).read())
      print(file_system.get(str(_id)).read())
      

      The error I got is:

      5e84dcec7ca83a32a5e09aa8
      5e84dcec7ca83a32a5e09aa8
      b'hello world'
      Traceback (most recent call last):
       File "duck.py", line 12, in <module>
       print(file_system.get(str(_id)).read())
       File "/usr/local/lib/python3.7/dist-packages/gridfs/__init__.py", line 153, in get
       gout._ensure_file()
       File "/usr/local/lib/python3.7/dist-packages/gridfs/grid_file.py", line 490, in _ensure_file
       (self.__files, self.__file_id))
      gridfs.errors.NoFile: no file in gridfs collection Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'my_app'), 'fs.files') with _id '5e84dcec7ca83a32a5e09aa8'
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            yingshaoxo@gmail.com yingshaoxo's lab
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: