⚠ Documentation version

These are the Git version docs. Docs for 0.4 (PyPI) are here.

Help out!

To make this documentation even better, we'd love to receive your feedback and suggestions for improvement!

GridFS Storage

class django_mongodb_engine.storage.GridFSStorage(location='', collection='storage', database='default', base_url=None)

GridFS Storage backend for Django.

This backend aims to add a GridFS storage to upload files to using Django’s file fields.

For performance, the file hirarchy is represented as a tree of MongoDB sub-collections.

(One could use a flat list, but to list a directory ‘/this/path/’ we would have to execute a search over the whole collection and then filter the results to exclude those not starting by ‘/this/path’ using that model.)

Parameters:
  • location – (optional) Name of the top-level node that holds the files. This value of location is prepended to all file paths, so it works like the location setting for Django’s built-in FileSystemStorage.
  • collection – Name of the collection the file tree shall be stored in. Defaults to ‘storage’.
  • database – Alias of the Django database to use. Defaults to ‘default’ (the default Django database).
  • base_url – URL that serves the files in GridFS (for instance, through nginx-gridfs). Defaults to None (file not accessible through a URL).