Hello. I just want to ask why JSONFileToSave class which is declared as
// Actually this is a helper object, not class, but this is not important
object JSONFileToSave {
def apply[N](filename: N,
contentType: Option[String] = None,
uploadDate: Option[Long] = None,
metadata: JsObject = Json.obj(),
id: JsValue = Json.toJson(UUID.randomUUID().toString)) // <- This is what is mean
(implicit naming: DefaultFileToSave.FileName[N]): JSONFileToSave = new JSONFileToSave(naming(filename), contentType, uploadDate, metadata, id)
}
Well, why it uses UUID as a default key instead of ObjectId? I've replaced it with newly generated ObjectId in my code, but I'm new to MongoDB and curious about such kind of decision
def save = SecuredAction.async(gridFSBodyParser(gridFS, (filename, contentType) =>
JSONFileToSave(id = Json.toJson(BSONObjectID.generate)(BSONObjectIDFormat), // <- Replace default implementation
filename = Some(filename), contentType = contentType))) { request =>
request.body.files.headOption.map(_.ref.mapTo[JSONReadFile].map { meta =>
log.debug(s"PDF $meta is saved successfully")
Created[JsValue](SuccessResponse.build(request, Json.toJson(meta)(JSONReadFileWriter.writes)))
}.recover {
// Handling and logging
}
}
I thought that default key should be ObjectId. At least it is preferred. Can you please explain why it is done is that way? Thanks
P.S. Play 2.3, ReactiveMongo 0.11