I have this code stanza in a repository's fetchVideos() method:
val find = collection.find(query).skip(numToSkip).limit(videosPerPage)
.sort(ascending("title")).collect()
val count = collection.countDocuments(query)
val zip = find.zip(count)
zip.head()
It is intended to return a future containing a tuple of:
- a subset of the Video objects in the database which match the given query filter
- the total count of Video objects in the database which match the given query filter
so, a
Future[(Seq[Video], Long)]
to enable pagination of search results for videos.
Instead, it often returns null as the future value. Not always, but usually. When null is not the future value, the result is often correct, though not always.
I have since gone on to serialize the two database accesses using a flatMap(), and that works as expected, but it seems to me like a bug that the above parallelization of these accesses does not also work.