Should the existing property be deleted before setting a new value? My implementation keeps adding new entries to files and chunks every time the property is updated.
Blob photo;
public void setPhoto(File file){
String type = MimeTypes.getContentType(file.getName());
photo = new Blob(file, type);
save();
}
Calling:
foo.setPhoto( barFile );
will store the file in gridfs as expected. Calling it again (to update with a new photo), the previous files remain in mongodb and the property returns the wrong file.
foo.photo.get();
Looking at the example of playmorphia, delete is not required but I am finding it necessary.
playmorphia v1.2.7 module
You probably want to do the delete yourself after you put the new in. I'd suggest following up with the play plugin people to see if there is an option which does this automatically and will return the latest photo.
I think you want to store a reference to the filename and not the id of the uploaded file if you want to get the latest one every time. So it would be more of a query than the _id. Once again, probably something to follow up with the play plugin people.