【发布时间】:2015-09-24 14:02:20
【问题描述】:
我需要一个var(以下为res)来接受find() 的答案,即MongoCursor,因为我必须能够访问我在if-conditions 中的变量(见下文)。
这是我正在做的事情:
var query = new MongoDBObject()
val res = ""
if ("condition_1" == field_1))
{
query += "field" -> "t"
if ("condition_2" == "field_2"))
{
res = collection.find(q).sort("basic_field" -> 1)
}
else if ("condition_2" == "field_2"))
{
res = collection.find(q).sort("important_field" -> -1).limit(101)
}
}
//Perform some operations on res
如何初始化我的res 以接受MongoCursor?
var res = MongoCursor 和 var res = DBCursor 不起作用。
【问题讨论】: