Skip to content

Revert v1.21 changes #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions source/includes/write/gridfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,11 @@ function toJSON(object $document): string
// end-download-to-stream

// Renames a file from the GridFS bucket with the specified ObjectId
// start-rename-files-id
// start-rename-files
$bucket->rename(new ObjectId('66e0a5487c880f844c0a32b1'), 'new_file_name');
// end-rename-files-id

// Renames files from the GridFS bucket with the specified filename
// start-rename-files-name
$bucket->renameByName('my_file', 'new_file_name');
// end-rename-files-name
// end-rename-files

// Deletes a file from the GridFS bucket with the specified ObjectId
// start-delete-files-id
// start-delete-files
$bucket->delete(new ObjectId('66e0a5487c880f844c0a32b1'));
// end-delete-files-id

// Deletes a file and its revisions from the GridFS bucket by name
// start-delete-files-name
$bucket->deleteByName('my_file');
// end-delete-files-name
// end-delete-files
4 changes: 0 additions & 4 deletions source/read/distinct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ options you can set to customize the operation:
- | The read preference to use for the operation. To learn more, see
:manual:`Read Preference </core/read-preference/>` in the Server manual.
| **Type**: ``MongoDB\Driver\ReadPreference``

* - ``hint``
- | The index to use for the operation.
| **Type**: ``string|object``

The following example retrieves the distinct values of the ``name`` field for
all documents that have a ``borough`` field value of ``'Bronx'`` and a
Expand Down
55 changes: 19 additions & 36 deletions source/write/gridfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,65 +375,48 @@ Rename Files
------------

Use the ``MongoDB\GridFS\Bucket::rename()`` method to update the name of
a GridFS file in your bucket. Pass the following parameters to the ``rename()``
method:

- ``_id`` value of the file you want to rename
- New file name
a GridFS file in your bucket. You must specify the file to rename by its
``_id`` field rather than its file name.

The following example shows how to update the ``filename`` field to
``'new_file_name'`` by referencing a file's ``_id`` value:
``'new_file_name'`` by referencing a document's ``_id`` field:

.. literalinclude:: /includes/write/gridfs.php
:language: php
:dedent:
:start-after: start-rename-files-id
:end-before: end-rename-files-id

Alternatively, you can use the ``MongoDB\GridFS\Bucket::renameByName()``
method to rename a GridFS file and all its file revisions. Pass the
following parameters to the ``renameByName()`` method:
:start-after: start-rename-files
:end-before: end-rename-files

- ``filename`` value you want to change
- New file name
.. note:: File Revisions

The following example renames all files that have a ``filename`` value
of ``'my_file'``:

.. literalinclude:: /includes/write/gridfs.php
:language: php
:dedent:
:start-after: start-rename-files-name
:end-before: end-rename-files-name
The ``rename()`` method supports updating the name of only one file at
a time. If you want to rename each file revision, or files with different upload
times that share the same file name, collect the ``_id`` values of each revision.
Then, pass each value in separate calls to the ``rename()`` method.

.. _gridfs-delete-files:

Delete Files
------------

Use the ``MongoDB\GridFS\Bucket::delete()`` method to remove a GridFS file's collection
Use the ``MongoDB\GridFS\Bucket::delete()`` method to remove a file's collection
document and associated chunks from your bucket. This effectively deletes the file.
Pass the ``_id`` value of the file you want to delete as a parameter to the
``delete()`` method.
You must specify the file by its ``_id`` field rather than its file name.

The following example shows you how to delete a file by referencing its ``_id`` field:

.. literalinclude:: /includes/write/gridfs.php
:language: php
:dedent:
:start-after: start-delete-files-id
:end-before: end-delete-files-id
:start-after: start-delete-files
:end-before: end-delete-files

Alternatively, you can use the ``MongoDB\GridFS\Bucket::deleteByName()`` method
to delete a GridFS file and all its file revisions. Pass the ``filename`` value of the
file you want to delete as a parameter to the ``deleteByName()`` method, as shown
in the following code:
.. note:: File Revisions

.. literalinclude:: /includes/write/gridfs.php
:language: php
:dedent:
:start-after: start-delete-files-name
:end-before: end-delete-files-name
The ``delete()`` method supports deleting only one file at a time. If
you want to delete each file revision, or files with different upload
times that share the same file name, collect the ``_id`` values of each revision.
Then, pass each value in separate calls to the ``delete()`` method.

API Documentation
-----------------
Expand Down
Loading