Skip to content
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

Add docs for GridFS adapter #1795

Merged
merged 2 commits into from
May 23, 2024
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
1 change: 1 addition & 0 deletions _data/menu_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Official Adapters:
AsyncAws S3: '/docs/adapter/async-aws-s3/'
Azure Blob Storage: '/docs/adapter/azure-blob-storage/'
Google Cloud Storage: '/docs/adapter/google-cloud-storage/'
MongoDB GridFS: '/docs/adapter/gridfs/'
SFTP (V2): '/docs/adapter/sftp-v2/'
SFTP (V3): '/docs/adapter/sftp-v3/'
WebDAV: '/docs/adapter/webdav/'
Expand Down
67 changes: 67 additions & 0 deletions docs/adapter/gridfs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
layout: default
title: MongoDB GridFS Adapter
permalink: /docs/adapter/gridfs/
redirect_from: /v2/docs/adapter/gridfs/
---

## Installation

```bash
composer require league/flysystem-gridfs:^3.0
```

## About

Interacting with MongoDB GridFS through Flysystem can be done
by using the `League\Flysystem\GridFS\GridFSAdapter`.

Read more about the MongoDB PHP Library in the [official documentation](https://www.mongodb.com/docs/php-library/).

## Simple usage:

```php
$client = new MongoDB\Client('mongodb://localhost:27017/');

// The internal adapter
$adapter = new League\Flysystem\GridFS\GridFSAdapter(
// GridFS Bucket
$client->selectDatabase('flysystem')->selectGridFSBucket()
);

// The FilesystemOperator
$filesystem = new League\Flysystem\Filesystem($adapter);
```

## Advanced usage:

```php
$client = new MongoDB\Client('mongodb://localhost:27017/');

// The internal adapter
$adapter = new League\Flysystem\GridFS\GridFSAdapter(
// GridFS Bucket
$client->selectDatabase('flysystem')->selectGridFSBucket([
// Bucket name in the MongoDB database
'bucketName' => 'project_files'
])
// Optional path prefix
'path/prefix',
);

// The FilesystemOperator
$filesystem = new League\Flysystem\Filesystem($adapter);
```

## Versioning:

In GridFS, file names are metadata to file objects identified by unique MongoDB `ObjectID`.
There may be more than one file with the same name, they are called "revisions":
- Reading a file reads the last revision of this file name
- Writing to a file name creates a new revision for this file name
- Renaming a file renames all the revisions of this file name
- Deleting a file deletes all the revisions of this file name

The GridFS Adapter for Flysystem does not provide access to a specific revision of a filename,
you must use the [GridFS API](https://www.mongodb.com/docs/php-library/current/tutorial/gridfs/)
if you need to work with revisions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ for which ever storage is right for you.
* **[AsyncAws S3](/docs/adapter/async-aws-s3/)**
* **[Google Cloud Storage](/docs/adapter/google-cloud-storage/)**
* **[Azure Blob Storage](/docs/adapter/azure-blob-storage/)**
* **[MongoDB GridFS](/docs/adapter/mongodb-gridfs/)**
* **[WebDAV](/docs/adapter/webdav/)**

### Third party Adapters
Expand Down