PYTHON-900 - Fix GridFS.delete().
This commit is contained in:
parent
81549e0608
commit
42fc925b11
@ -41,15 +41,9 @@ class GridFS(object):
|
||||
Raises :class:`TypeError` if `database` is not an instance of
|
||||
:class:`~pymongo.database.Database`.
|
||||
|
||||
The `connect` parameter ensures that the underlying
|
||||
:class:`~pymongo.mongo_client.MongoClient` is connected to a server,
|
||||
and creates an index on the "chunks" collection if needed.
|
||||
|
||||
:Parameters:
|
||||
- `database`: database to use
|
||||
- `collection` (optional): root collection to use
|
||||
- `connect` (optional): whether to begin connecting the client in
|
||||
the background
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
`database` must use an acknowledged
|
||||
@ -235,8 +229,8 @@ class GridFS(object):
|
||||
- `file_id`: ``"_id"`` of the file to delete
|
||||
"""
|
||||
self.__ensure_index_files_id()
|
||||
self.__files.delete_many({"_id": file_id})
|
||||
self.__chunks.delete_one({"files_id": file_id})
|
||||
self.__files.delete_one({"_id": file_id})
|
||||
self.__chunks.delete_many({"files_id": file_id})
|
||||
|
||||
def list(self):
|
||||
"""List the names of all files stored in this instance of
|
||||
|
||||
@ -117,6 +117,18 @@ class TestGridfs(IntegrationTest):
|
||||
self.assertEqual("foo", oid)
|
||||
self.assertEqual(b"hello world", self.fs.get("foo").read())
|
||||
|
||||
def test_multi_chunk_delete(self):
|
||||
self.db.fs.drop()
|
||||
self.assertEqual(0, self.db.fs.files.count())
|
||||
self.assertEqual(0, self.db.fs.chunks.count())
|
||||
gfs = gridfs.GridFS(self.db)
|
||||
oid = gfs.put("hello", chunkSize=1)
|
||||
self.assertEqual(1, self.db.fs.files.count())
|
||||
self.assertEqual(5, self.db.fs.chunks.count())
|
||||
gfs.delete(oid)
|
||||
self.assertEqual(0, self.db.fs.files.count())
|
||||
self.assertEqual(0, self.db.fs.chunks.count())
|
||||
|
||||
def test_list(self):
|
||||
self.assertEqual([], self.fs.list())
|
||||
self.fs.put(b"hello world")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user