I am using Mongo Scala Driver to read documents from MongoDb. I have following method as follow which returns Future[List[T]]
def findAll(): List[Future[List[T]] = {
db.getCollection(collectionName)
.find(queryObject)
.toFuture()
.map{
results => results.map(/* converting result to T */).toList
}
}
Question:
Instead of a List, is there some way, this method can return Iterator[T]
or Future[Iterator[T]]
?
The doc mentions about iterating the results via the subscribe method
, but I cannot find any concrete implementation or examples of using this subscribe
method to achieve my use case.