Download the PHP package mts88/mongogrid without Composer
On this page you can find all versions of the php package mts88/mongogrid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mongogrid
Laravel MongoDB GridFS
A library wants to help the use of GridFS of MongoDB for Laravel 5. This library extends the original MongoDB GridFS Bucket for PHP, so many methods are exactly the same and others are simplified for the use.
Note
This is not a library for Eloquent or somenthing like this. It's a simple helper to easly use GridFS in Laravel. If you are looking for an Eloquent Model for MongoDB I suggest you jenssegers/laravel-mongodb.
Table of contents
- Installation
- Configuration
- Usage
- Bucket Prefix
- Storing File
- Get File
- Helpers
- Contact
- License
Installation
Laravel version Compatibility
Laravel | Package |
---|---|
< 5.5.x | 1.1.x (not tested) |
>= 5.5.x | 1.1.x |
Requirements
Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php
Installation
-
Installation using composer:
-
And add the service provider in
config/app.php
: - You may also register an alias for the MongoGrid library by adding the following to the alias array in
config/app.php
:
Configuration
Run the command below to publish the package config file config/gridfs.php
:
MongoDB Connection
You can use build-in configuration in config/gridfs.php
or you can use config/database.php
(compatible with jenssegers/laravel-mongodb).
Connection with config/gridfs.php
In config file config/gridfs.php
set up your configuration in order to connect to MongoDB:
Simple Connection
ReplicaSet Connection
In your .env
file add DB_REPLICA_SET
property with the name of Replica Set
Connection with config/database.php
In config file config/gridfs.php
set up your configuration name:
In config file config/database.php
set up your configuration in order to connect to MongoDB:
And add a new mongodb connection:
Simple Connection
ReplicaSet Connection
You can connect to multiple servers or replica sets with the following configuration:
DSN URL
Alternatively, you can use MongoDB connection string:
Please refer to MongoDB official docs for its URI format: https://docs.mongodb.com/manual/reference/connection-string/
Bucket Configuration
This is the config for GridFS Bucket:
For more details see MongoDB GridFS Bucket.
Metadata
By default the library adds these metadata to each document:
- uuid;
- created_at;
- updated_at;
- downloads;
set false
in config/gridfs.php
file to not include this info.
Temporary Storage
By default the library use local
driver for storing file into MongoDB. You can change the default driver of the Storage
:
To learn more see Laravel File Storage.
Usage
Bucket Prefix
By default MongoGrid use the prefix in config/gridfs.php
, but if you want you can use another custom prefix on the fly:
Storing File
storeFile( $fileContent, $fileName, [ optional $metadata] )
Store a file using contents, file name and your metadata (optional). Returns ObjectId
Or using another prefix
Get File
All method to get files from GridFS. Revision numbers are defined as follows:
- 0 = the original stored file
- 1 = the first revision
- 2 = the second revision
- etc…
- -2 = the second most recent revision
- -1 = the most recent revision
Defaults to -1 (i.e. the most recent revision). Revision works only on method by filename.
getFileContent( $source, [optional $revision] )
You can retrive the content of file by his name or his ObjectId. You can use also the revision of the file.
getFile( $source )
You can retrive the content of file by his name or his ObjectId. Returns a document of the file collection.
findOne( $query, [ optional $options ] )
Finds a single document from the selected GridFS bucket matching the query.
To learn more about $options
see MongoDB GridFS findOne.
find( $query, [ optional $options ] )
Finds all documents from the selected GridFS bucket matching the query.
download( $source, string $path, [optional $revision] )
Download a file from GridFS to a given path
NB: downloading a file with this method will increments downloads on metadata by itself (only if metadata are active).
Helpers
rename( $_id, $newName )
Rename a file.
delete( $_id )
Delete a file from the collection.
getBucketName()
Return the Collection Chunks of the selected GridFS Bucket
getChunksCollection()
Returns the name of the selected GridFS Bucket
getChunkSizeBytes()
Return the size of Chunks of the selected GridFS Bucket
getDatabaseName()
Return the name of the database used for selected GridFS
getFilesCollection()
Return the Collection File of the selected GridFS Bucket
drop()
Drop entire collections of a selected GridFS
Contact
Open an issue on GitHub if you have any problems or suggestions.
License
The contents of this repository is released under the MIT license.