Skip to content

Create a GridFS file instead of a collection #486

Closed
wants to merge 1 commit into from

2 participants

@MDrollette

When using the "odm:schema:create" command it would create a GridFS file collection as a regular collection. This creates the proper GridFS files collection instead.

@jmikola
Doctrine member
jmikola commented Jan 31, 2013

Instantiating the MongoGridFS class doesn't actually create anything on the server. Are you sure this is actually creating a collection, or is it NOP-ing in the case of a file?

Technically, both GridFS collections are normal collections -- they just have a specific naming convention. It may be more reasonable to call createCollection() with the appropriate name (e.g. fs.files).

@MDrollette

Without this change, when I run the schema:create command I get these collections created. There shouldn't be an Asset collection.

> show collections
Asset
Asset.files
system.indexes

It may be better to explicitly create the Asset.files and Asset.chunks collections, but I assumed the driver handled that automatically when you instantiated MongoGridFS http://www.php.net/manual/en/mongogridfs.construct.php

@jmikola
Doctrine member
jmikola commented Feb 1, 2013

What is actually creating the Asset.files collection? The reason I mention the NOP, is because:

$this->dm->getDocumentDatabase($documentName)->getGridFS($class->getCollection());

...shouldn't do anything at all on the server-side. It's going to instantiate a MongoGridFS class that quickly falls out of scope in this PHP method. I think it'd be better to simply do:

if ($class->isFile()) {
    return;
}

...between the exception for mapped superclasses and the existing createCollection() call. Otherwise, we could amend the createCollection() code to actually create a *.files collection, but someone is bound to shoot themselves in the foot that way. If you created a capped fs.files collection and it fills up, you're going to end up with orphan chunks in the fs.chunks collection at some point.

@jmikola jmikola added a commit that closed this pull request Apr 1, 2013
@jmikola jmikola Create GridFS collections in SchemaManager (closes #486)
GridFS collections should never use capped collections, so we can ignore those options from ClassMetadataInfo.
517e0a5
@jmikola jmikola closed this in 517e0a5 Apr 1, 2013
@jmikola
Doctrine member
jmikola commented Apr 1, 2013

@MDrollette: Please take a look at 517e0a5. I believe that addresses your concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.