meraj
meraj

Reputation: 195

"AttributeError: 'GridFS' object has no attribute 'find'"

I am using pymongo version 2.6.3, I am saving file in mongo in gridfs, suddenly gridfs is giving error. AttributeError: 'GridFS' object has no attribute 'find' my code is:

import gridfs
admin_db = MDB_CONN['admin']
admin_db.authenticate(mongo_admin, mongo_password)
db = MDB_CONN["dbname"]
grid = gridfs.GridFS(db,collection="collectionName")
grid_cursor = grid.find({'file_hash':self.object_id},timeout=False, limit=1)

Thanks in advance for your help.

Upvotes: 1

Views: 1623

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174624

You are getting this error because there is no find() method in version 2.6.3 of the driver; it was added in version 2.7:

PyMongo 2.7 is a major release with a large number of new features and bug fixes. Highlights include:

  • Full support for MongoDB 2.6.
  • A new bulk write operations API.
  • Support for server side query timeouts using max_time_ms().
  • Support for writing aggregate() output to a collection.
  • A new parallel_scan() helper.
  • OperationFailure and its subclasses now include a details attribute with complete error details from the server.
  • A new GridFS find() method that returns a GridOutCursor.
  • Greatly improved support for mod_wsgi when using PyMongo’s C extensions. Read Jesse’s blog post for details.
  • Improved C extension support for ARM little endian.

You should upgrade your driver to the latest supported version.

Upvotes: 1

Related Questions