Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Created March 16, 2018 12:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Mapping file uploads with Doctrine MongoDB ODM
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
<document name="Acme\Domain\Model\Photo\Photo" collection="photos">
<field fieldName="_id" id="true" />
<field fieldName="galleryId" type="string" />
<field fieldName="description" type="string" />
<reference-one field="photoFile" target-document="Acme\Domain\Model\Photo\PhotoFile"
simple="true" orphan-removal="true">
<cascade>
<persist/>
</cascade>
</reference-one>
</document>
</doctrine-mongo-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
<document name="Acme\Domain\Model\Photo\PhotoFile" collection="photos.files">
<field fieldName="id" id="true" />
<field fieldName="file" type="file"/>
<field fieldName="filename" type="string"/>
<field fieldName="mimeType" type="string"/>
<field fieldName="uploadDate" type="string"/>
<field fieldName="length" type="string"/>
<field fieldName="chunkSize" type="string"/>
<field fieldName="md5" type="string"/>
</document>
</doctrine-mongo-mapping>
@webdevilopers
Copy link
Author

Came from:

When mapping and uploading files w/ #MongoDB and #DoctrineODM I currently split the actual "file" from my "#domainmodel" in order to add some extra properties to the latter only. Do you prefer too split them too or keep all the info inside one Document?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment