How do I create a GridFS bucket?

57 views
Skip to first unread message

John

unread,
Nov 21, 2018, 3:45:15 PM11/21/18
to mongodb-user
I'm using the MongoDB PHP library installed via Composer.

I'm trying to use GridFS but can't for the life of me figure out how to create a GridFS bucket I can then later upload to and download from. The documentation doesn't seem to have a step by step guide for doing this and there's very little in the way of suggestions on Stackoverflow etc.

Is it even true that I need to create a bucket? Is a bucket simply another name for an existing collection or do I have to execute a command somewhere to actually create a GridFS bucket?

Very confused :-/


Jeremy Mikola

unread,
Nov 21, 2018, 4:03:53 PM11/21/18
to mongod...@googlegroups.com
The library's documentation does have a GridFS tutorial that walks through various examples of uploading and downloading files. The concept of a bucket is very much like a collection in that it does not need to be explicitly created. By creating a bucket object in the library, you are merely specifying the prefix of the collections that will be used (e.g. "fs" for "fs.files" and "fs.chunks") and other default options, such as chunk size or write concern, for any upload/download operations performed with that bucket object.

If the file and chunk collections do not exist at the time you upload a file, they will be created for you. Likewise, attempting to download files from a bucket object where the file and chunk collections do not exist will simply return no results -- much like calling MongoDB\Collection::find() on a nonexistent collection.

Reply all
Reply to author
Forward
0 new messages