I have the following code to write a gridfs file:
request.body.files.toList.lastOption match {
case Some(picture) => {
val filename = picture.filename
val contentType = picture.contentType
picture.ref.moveTo(new File("/tmp/" + filename), true)
val gridFS = new GridFS(db, "attachments")
val fileToSave = DefaultFileToSave(filename, contentType)
val futureResult: Future[ReadFile[BSONValue]] = gridFS.writeFromInputStream(fileToSave, new FileInputStream(new File("/tmp/" + filename)))
...
The code works fine but it duplicates the files in the collection when I write two files with the same name. I thought to create a unique index using the filename field but that would keep the first file and I need to keep the newest version. How can I do it?
Thanks,
GA