Public Member Functions | |
| def | __init__ |
| def | delete |
| def | exists |
| def | get |
| def | get_last_version |
| def | get_version |
| def | list |
| def | new_file |
| def | open |
| def | put |
| def | remove |
Private Attributes | |
| __chunks | |
| __collection | |
| __database | |
| __files | |
An instance of GridFS on top of a single Database.
Definition at line 32 of file gridfs/__init__.py.
| def gridfs::GridFS::__init__ | ( | self, | ||
| database, | ||||
collection = "fs" | ||||
| ) |
Create a new instance of :class:`GridFS`. Raises :class:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. :Parameters: - `database`: database to use - `collection` (optional): root collection to use .. versionadded:: 1.6 The `collection` parameter. .. mongodoc:: gridfs
Definition at line 35 of file gridfs/__init__.py.
| def gridfs::GridFS::delete | ( | self, | ||
| file_id | ||||
| ) |
Delete a file from GridFS by ``"_id"``. Removes all data belonging to the file with ``"_id"``: `file_id`. .. warning:: Any processes/threads reading from the file while this method is executing will likely see an invalid/corrupt file. Care should be taken to avoid concurrent reads to a file while it is being deleted. .. note:: Deletes of non-existent files are considered successful since the end result is the same: no file with that _id remains. :Parameters: - `file_id`: ``"_id"`` of the file to delete .. versionadded:: 1.6
Definition at line 188 of file gridfs/__init__.py.
| def gridfs::GridFS::exists | ( | self, | ||
document_or_id = None, |
||||
| kwargs | ||||
| ) |
Check if a file exists in this instance of :class:`GridFS`.
The file to check for can be specified by the value of it's
``_id`` key, or by passing in a query document. A query
document can be passed in as dictionary, or by using keyword
arguments. Thus, the following three calls are equivalent:
>>> fs.exists(file_id)
>>> fs.exists({"_id": file_id})
>>> fs.exists(_id=file_id)
As are the following two calls:
>>> fs.exists({"filename": "mike.txt"})
>>> fs.exists(filename="mike.txt")
And the following two:
>>> fs.exists({"foo": {"$gt": 12}})
>>> fs.exists(foo={"$gt": 12})
Returns ``True`` if a matching file exists, ``False``
otherwise. Calls to :meth:`exists` will not automatically
create appropriate indexes; application developers should be
sure to create indexes if needed and as appropriate.
:Parameters:
- `document_or_id` (optional): query document, or _id of the
document to check for
- `**kwargs` (optional): keyword arguments are used as a
query document, if they're present.
.. versionadded:: 1.8
Definition at line 219 of file gridfs/__init__.py.
| def gridfs::GridFS::get | ( | self, | ||
| file_id | ||||
| ) |
Get a file from GridFS by ``"_id"``. Returns an instance of :class:`~gridfs.grid_file.GridOut`, which provides a file-like interface for reading. :Parameters: - `file_id`: ``"_id"`` of the file to get .. versionadded:: 1.6
Definition at line 119 of file gridfs/__init__.py.
| def gridfs::GridFS::get_last_version | ( | self, | ||
| filename | ||||
| ) |
Get the most recent version of a file in GridFS by ``"filename"``. Equivalent to calling :meth:`get_version` with the default `version` (``-1``). :Parameters: - `filename`: ``"filename"`` of the file to get .. versionadded:: 1.6
Definition at line 174 of file gridfs/__init__.py.
| def gridfs::GridFS::get_version | ( | self, | ||
| filename, | ||||
version = -1 | ||||
| ) |
Get a file from GridFS by ``"filename"``.
Returns a version of the file in GridFS with the name
`filename` as an instance of
:class:`~gridfs.grid_file.GridOut`. Version ``-1`` will be the
most recently uploaded, ``-2`` the second most recently
uploaded, etc. Version ``0`` will be the first version
uploaded, ``1`` the second version, etc. So if three versions
have been uploaded, then version ``0`` is the same as version
``-3``, version ``1`` is the same as version ``-2``, and
version ``2`` is the same as version ``-1``.
Raises :class:`~gridfs.errors.NoFile` if no such version of
that file exists.
An index on ``{filename: 1, uploadDate: -1}`` will
automatically be created when this method is called the first
time.
:Parameters:
- `filename`: ``"filename"`` of the file to get
- `version` (optional): version of the file to get (defualts
to -1, the most recent version uploaded)
.. versionadded:: 1.9
Definition at line 132 of file gridfs/__init__.py.
| def gridfs::GridFS::list | ( | self | ) |
List the names of all files stored in this instance of :class:`GridFS`. .. versionchanged:: 1.6 Removed the `collection` argument.
Definition at line 210 of file gridfs/__init__.py.
| def gridfs::GridFS::new_file | ( | self, | ||
| kwargs | ||||
| ) |
Create a new file in GridFS. Returns a new :class:`~gridfs.grid_file.GridIn` instance to which data can be written. Any keyword arguments will be passed through to :meth:`~gridfs.grid_file.GridIn`. If the ``"_id"`` of the file is manually specified, it must not already exist in GridFS. Otherwise :class:`~gridfs.errors.FileExists` is raised. :Parameters: - `**kwargs` (optional): keyword arguments for file creation .. versionadded:: 1.6
Definition at line 60 of file gridfs/__init__.py.
| def gridfs::GridFS::open | ( | self, | ||
| args, | ||||
| kwargs | ||||
| ) |
No longer supported. .. versionchanged:: 1.6 The open method is no longer supported.
Definition at line 258 of file gridfs/__init__.py.
| def gridfs::GridFS::put | ( | self, | ||
| data, | ||||
| kwargs | ||||
| ) |
Put data in GridFS as a new file. Equivalent to doing: >>> f = new_file(**kwargs) >>> try: >>> f.write(data) >>> finally: >>> f.close() `data` can be either an instance of :class:`str` or a file-like object providing a :meth:`read` method. If an `encoding` keyword argument is passed, `data` can also be a :class:`unicode` instance, which will be encoded as `encoding` before being written. Any keyword arguments will be passed through to the created file - see :meth:`~gridfs.grid_file.GridIn` for possible arguments. Returns the ``"_id"`` of the created file. If the ``"_id"`` of the file is manually specified, it must not already exist in GridFS. Otherwise :class:`~gridfs.errors.FileExists` is raised. :Parameters: - `data`: data to be written as a file. - `**kwargs` (optional): keyword arguments for file creation .. versionadded:: 1.9 The ability to write :class:`unicode`, if an `encoding` has been specified as a keyword argument. .. versionadded:: 1.6
Definition at line 78 of file gridfs/__init__.py.
| def gridfs::GridFS::remove | ( | self, | ||
| args, | ||||
| kwargs | ||||
| ) |
No longer supported. .. versionchanged:: 1.6 The remove method is no longer supported.
Definition at line 266 of file gridfs/__init__.py.
gridfs::GridFS::__chunks [private] |
Definition at line 56 of file gridfs/__init__.py.
gridfs::GridFS::__collection [private] |
Definition at line 54 of file gridfs/__init__.py.
gridfs::GridFS::__database [private] |
Definition at line 53 of file gridfs/__init__.py.
gridfs::GridFS::__files [private] |
Definition at line 55 of file gridfs/__init__.py.