该代码使用 ReactiveMongo 向 MongoDB 发送请求并返回Future[BSONDocument]
,但我的代码处理数据列表,因此我需要获取 的值,Future[BSONDocument]
然后将其转换为列表。
我如何在不阻塞的情况下做到这一点?
更新:
我正在使用 ReactiveMongoRawCommand
def findLByDistance()(implicit ec: ExecutionContext) = db.command(RawCommand(
BSONDocument(
"aggregate" -> collName,
"pipeline" -> BSONArray(BSONDocument(
"$geoNear" -> BSONDocument(
"near" -> BSONArray(44.72,25.365),
"distanceField" -> "location.distance",
"maxDistance" -> 0.08,
"uniqueDocs" -> true)))
)))
结果出来了Future[BSONDocument]
。对于一些简单的查询,我使用了允许简单转换的默认查询生成器
def findLimitedEvents()(implicit ec: ExecutionContext) =
collection.find(BSONDocument.empty)
.query(BSONDocument("tags" -> "lazy"))
.options(QueryOpts().batchSize(10))
.cursor.collect[List](10, true)
我基本上需要RawCommand
输出类型来匹配以前使用的。