Pymongo GridFS vs GridFSBucket

155 views
Skip to first unread message

Raghuram Krishnaswami

unread,
Nov 29, 2018, 3:18:24 AM11/29/18
to mongodb-user
The pymongo documentation seems to be light on gridfs.
I found this example, which only uses the `gridfs.GridFS`. But the API Reference has another class `gridfs.GridFSBucket`.
I'm not understanding why there are two different classes, and the difference between the two.

Why am I interested in this?
Because I use PyMODM, and internally, it is using `gridfs.GridFSBucket.open_download_stream` (in `GridFSFile` class).



Wan Bachtiar

unread,
Jan 9, 2019, 7:30:56 PM1/9/19
to mongodb-user

I’m not understanding why there are two different classes, and the difference between the two.

Hi Raghuram,

gridfs.GridFSBucket is a new top level object that is added to follow methods defined in MongoDB Drivers: GridFS Spec, i.e. upload_from_stream, etc.

For PyMongo, GridFSBucket is introduced in version 3.1.

Regards,
Wan.

Bernie Hackett

unread,
Jan 9, 2019, 10:02:19 PM1/9/19
to mongodb-user
To add a small amount of background to Wan's (totally correct) answer. GridFSBucket was added because we decided to write an actual client side GridFS spec with a unified API for all MongoDB drivers. The older GridFS API in PyMongo isn't going anywhere. It's been around for so long that removing it would break far too many applications.

Raghuram Krishnaswami

unread,
Jan 10, 2019, 12:48:29 AM1/10/19
to mongodb-user
Thank you Wan and Bernie.


> To add a small amount of background to Wan's (totally correct) answer. GridFSBucket was added because we decided to write an actual client side GridFS spec with a unified API for all MongoDB drivers. The older GridFS API in PyMongo isn't going anywhere. It's been around for so long that removing it would break far too many applications.

Does this mean that newer applications should prefer GridFSBucket?
Even if the old API isn't going anywhere, it's still better to use the newer API, since it would be up-to-date with the GridFS Spec...


Reply all
Reply to author
Forward
0 new messages