I am trying to insert a bunch of pdf-files into MongoDB using GridFS, but get a MongoGridFSException
with the message: error setting up file name in path, where name is the absolute path to the pdf-document on the file system.
I'm using a very simple CLI-script:
$it = new DirectoryIterator(__DIR__ .'/files');
while ($it as $file) {
$grid->storeFile($file->getPathname(), array('metadata' => $metadata));
}
I find the lack of documentation for GridFS disturbing. The examples in MongoGridFS and storeFile() all just show a simple filename as first argument; if the data is retrieved from this filename, what basePath does the script assume (cwd
, __DIR__
or something completely different?) or can I just add the absolute path (judging from the error message, probably not)?
I was contemplating on using storeBytes(file_get_contents($file->getPathname())
instead, but then how do I retrieve the file, when there is no filename associated with it? Do I add the filename in the 2nd argument (options-array)?
Also, if I want to know the mine/type of a stored file, do I have to specify it in the metadata manually or is this determined automatically when inserting the file?
TL;DR: I have no idea how to work with GridFS and the php-docs are of poor quality. Can at the very least, someone point out better examples/documentation?