Skip to content

3. GridFS File Storage

Jon Clausen edited this page Jan 1, 2016 · 19 revisions

CBMongoDB includes an interface and Active Entity implementation for using MongoDB's GridFS for relational, distributed file storage. Let's say, for example, that we want to associate profile images to our people collection.

Let's create a relational entity that will be responsible for storing and retrieving profile pictures. Our component should extend cbmongodb.models.FileEntity. An additional component attribute may be specified with the name of the bucket used to store the file data. By default, Mongo uses a bucket named fs.

component name="ProfileImages" extends="cbmongodb.models.FileEntity" collection="profileImages" bucket="images" accessors=true{
	//normalize our person information, in case we need it for captions and alt information.
	property name="person" schema=true normalize="Person" on="person.id" keys="first_name,last_name";
		property name="person.id" schema=true required=true;	
}