Casbah returns DBObject 而不是 MongoDBObject
Casbah returns DBObject instead of MongoDBObject
findOne Returns an Option - either Some(MongoDBObject) or None
然而,findOne
实际上给了我一个 Option
而不是普通的 Some(DBObject)
:
scala> MongoClient("localhost", 27017)("db")("collection").findOne()
res0: Option[com.mongodb.DBObject] = Some({ "_id" : { "$oid" : "559860491b07c0dc5b52f3ee"} , "description" : "Some text" })
find
也是如此,它 returns 是 DBObject
个实例的迭代器。经过数小时的谷歌搜索和摸不着头脑后,我不知所措。
这是怎么回事?我仍在学习 Scala,所以可能有些细微差别我没有理解。
教程中的示例 return 很简单 DBObject
s,所以我认为这只是文档中的一个错误。
Casbah 提供 DBObject
和 MongoDBObject
之间的隐式(自动)转换 - 如此处所述:
There is an implicit conversion loaded that can Pimp any DBObject as MongoDBObject
We automatically provide implicit methods which convert DBObject to
MongoDBObject. Any method which needs a MongoDBObject will accept a
DBObject fine as long as you ran the imports.
您需要使用以下方法导入转换才能工作:
import com.mongodb.casbah.Imports._
findOne Returns an Option - either Some(MongoDBObject) or None
然而,findOne
实际上给了我一个 Option
而不是普通的 Some(DBObject)
:
scala> MongoClient("localhost", 27017)("db")("collection").findOne()
res0: Option[com.mongodb.DBObject] = Some({ "_id" : { "$oid" : "559860491b07c0dc5b52f3ee"} , "description" : "Some text" })
find
也是如此,它 returns 是 DBObject
个实例的迭代器。经过数小时的谷歌搜索和摸不着头脑后,我不知所措。
这是怎么回事?我仍在学习 Scala,所以可能有些细微差别我没有理解。
教程中的示例 return 很简单 DBObject
s,所以我认为这只是文档中的一个错误。
Casbah 提供 DBObject
和 MongoDBObject
之间的隐式(自动)转换 - 如此处所述:
There is an implicit conversion loaded that can Pimp any DBObject as MongoDBObject
We automatically provide implicit methods which convert DBObject to MongoDBObject. Any method which needs a MongoDBObject will accept a DBObject fine as long as you ran the imports.
您需要使用以下方法导入转换才能工作:
import com.mongodb.casbah.Imports._