I was wondering why the following function doesMsgExist()
always returns false
even when the results from the DB is not empty.
def doesMsgExist(name: String, age: String): Boolean = {
var result = false
val msgExistsFlag = checkExistingMessages(db.getDocument(name, age))
msgExistsFlag.foreach(isTrue => result = if(isTrue) false else true)
result
}
def checkExistingMessages(resultFromDB: Future[List[BSONDocument]]): Future[Boolean] = {
resultFromDB.map { list =>
if (list.isEmpty) {
false
}
else true
}
}