Commits

Liam Staskawicz  committed 2fb6298

* a couple more DB commands

  • Participants
  • Parent commits d668db8

Comments (0)

Files changed (2)

       throw MongoOpErr("dropDatabase failed: ${res}")
   }
   
+  **
+  ** List all databases known on the DB server
+  ** Each item returned is a Map with the Str keys: "name", "sizeOnDisk" and "empty"
+  ** Note - you must be authenticated for this to succeed
+  **
+  List listDatabases()
+  {
+    res := command(["listDatabases": 1], true)
+    if(!cmdOk(res))
+      throw MongoOpErr("listDatabases failed: ${res}")
+    return res["databases"]
+  }
+  
+  **
+  ** Returns status info about the DB server - uptime, lock info, memory info
+  **
+  Map serverStatus()
+  {
+    // weird...doesn't return an "ok" in the response...just return it directly
+    return command(["serverStatus": 1])
+  }
+  
+  **
+  ** Repair/compact this DB.
+  **
+  Void repair(Bool preserveClonedFilesOnFailure, Bool backupOriginalFiles)
+  {
+    c := Str:Obj [:] { ordered = true }
+    c["repairDatabase"] = 1
+    c["preserveClonedFilesOnFailure"] = preserveClonedFilesOnFailure
+    c["backupOriginalFiles"] = backupOriginalFiles
+    res := command(c)
+    if(!cmdOk(res))
+      throw MongoOpErr("repairDatabase error - $res")
+  }
+  
 }

File test/DBTest.fan

     verifyFalse(db.collectionNames().contains(fullname))
   }
   
+  Void testServerStatus()
+  {
+    ss := db.serverStatus
+    verify(ss.keys.containsAll(["uptime", "globalLock", "mem"]))
+  }
+  
+  Void testListDatabases()
+  {
+    db.listDatabases.each |Map v, i| {
+      verify(v.keys.containsAll(["name", "sizeOnDisk", "empty"]))
+    }
+  }
+  
+  Void testRepair()
+  {
+    db.repair(true, true) // just run it...make sure no Errs are thrown
+  }
+  
 }