Mongo从casbah获取db.serverstatus

时间:2013-11-28 17:03:13

标签: mongodb scala casbah

有没有办法获得

的结果
db.serverStatus() 
来自 casbah 来处理它们?

我特别需要连接,网络,指标字段。

由于

1 个答案:

答案 0 :(得分:2)

    import com.mongodb.casbah.Imports._ 

    //connect to MongoDB, testDB is the name of database
    val test = MongoClient()("testDB")
    // run serverStatus command
    val status = test.command("serverStatus")
    // status is an instance of BasicDBObject 
    //retrieving number of available connections
    val availableConnections = status.get("connections").asInstanceOf[BasicDBObject].get("available")