If possible, I would like to return the ObjectId() generated by mongo after insertOne operation
def insert(inputDocument : Map[String,Any], databaseName : String, collectionName : String, mongoClient : MongoClient)
: Future[Completed] = {
implicit val formats: DefaultFormats.type = DefaultFormats
val createdAt = new Date()
val createdAtUnix = System.currentTimeMillis()
val insertJson = write( inputDocument ++ Map("createdAt" -> createdAt, "createdAtUnix" -> createdAtUnix))
val database: MongoDatabase = mongoClient.getDatabase(databaseName)
val collection: MongoCollection[Document] = database.getCollection(collectionName)
val insertDocument = Document(insertJson)
collection
.insertOne(insertDocument)
.toFuture()
}
If not possible, i know it is possible to generate one, but how to be sure it's unique ?