Below you will find pages that utilize the taxonomy term “MongoDB”
Combining GridFS files with ORM entities
In my previous post I wrote about uploading files to GridFS. Therefor I created a MongoDB Document with a $file
property annotated with @MongoDB\File
. Because I am using ORM entities more often then ODM documents, I was looking for a seamless way to access a Document from an Entity.
Because it isn’t possible to define a direct relationship between an Entity and a Document I thought it would be a solid solution to create a custom field type. By defining a custom field type I can control the way the reference to the Document will be stored and at the same time I will be able to restore the reference when retrieving the field. The steps needed to create a custom field type for ORM entities are very similar to the post of Matthias on how to create custom field types for ODM documents.
Uploading files to MongoDB GridFS
Almost at the same time, I silently celebrate the first birthday of my blog. My first article appeared a little over a year ago. It is great to see how Symfony2 has become more and more popular during these twelve months. Your comments and visits encourage me to keep posting articles. So, thank you all! And thanks, Dennis, for contributing.
GridFS is a specification for storing large files in MongoDB. In this post I will explain how you can easily upload a file to GridFS and then retrieve it from the database to serve it to the browser.