我有以下代码来编写 gridfs 文件:
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)))
...
该代码工作正常,但是当我编写两个同名文件时,它会复制集合中的文件。我想使用文件名字段创建一个唯一索引,但这会保留第一个文件,我需要保留最新版本。我该怎么做?
谢谢,
遗传算法