From 1184fce8c38784ce1143a3586a14240950590ce4 Mon Sep 17 00:00:00 2001 From: "Michael S. Klishin" Date: Fri, 8 Jun 2012 22:04:46 +0400 Subject: [PATCH] Add a few more commands that may be useful to JVM-based applications Clojure is unlikely to be a good choice for devops tools, so we don't implement convenience functions for sharding, replication, et cetera. --- src/monger/command.clj | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/monger/command.clj b/src/monger/command.clj index 630abf2..dac6e0a 100644 --- a/src/monger/command.clj +++ b/src/monger/command.clj @@ -28,11 +28,41 @@ (defn reindex-collection - ([collection] + "Forces an existing collection to be reindexed using the reindexCollection command" + ([^String collection] (reindex-collection monger.core/*mongodb-database* collection)) - ([^DB database collection] + ([^DB database ^String collection] (monger.core/command database { :reIndex collection }))) +(defn rename-collection + "Changes the name of an existing collection using the renameCollection command" + ([^String from ^String to] + (reindex-collection monger.core/*mongodb-database* from to)) + ([^DB database ^String from ^String to] + (monger.core/command database { :renameCollection from :to to }))) + +(defn convert-to-capped + "Converts an existing, non-capped collection to a capped collection using the convertToCapped command" + ([^String collection ^long size] + (convert-to-capped monger.core/*mongodb-database* collection size)) + ([^Db database ^String collection ^long size] + (monger.core/command database {:convertToCapped collection :size size}))) + +(defn empty-capped + "Removes all documents from a capped collection using the emptycapped command" + ([^String collection] + (empty-capped monger.core/*mongodb-database* collection)) + ([^Db database ^String collection] + (monger.core/command database {:emptycapped collection}))) + + +(defn compact + "Rewrites and defragments a single collection using the compact command. This also forces all indexes on the collection to be rebuilt" + ([^String collection] + (compact monger.core/*mongodb-database* collection)) + ([^Db database ^String collection] + (monger.core/command database {:compact collection}))) + (defn server-status ([]