From a121598651324d1ae1a68e653f28b0c56eae3a23 Mon Sep 17 00:00:00 2001 From: Tom McNulty Date: Thu, 10 Jan 2013 20:32:48 -0700 Subject: [PATCH 1/2] Close DBCursors in find-maps/find-seq --- src/clojure/monger/collection.clj | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/clojure/monger/collection.clj b/src/clojure/monger/collection.clj index 680452c..0b9a73a 100644 --- a/src/clojure/monger/collection.clj +++ b/src/clojure/monger/collection.clj @@ -164,24 +164,32 @@ If you want to work directly with DBObject, use find. " ([^String collection] - (map (fn [x] (from-db-object x true)) (find collection))) + (with-open [dbc (find collection)] + (map (fn [x] (from-db-object x true)) dbc))) ([^String collection ^Map ref] - (map (fn [x] (from-db-object x true)) (find collection ref))) + (with-open [dbc (find collection ref)] + (map (fn [x] (from-db-object x true)) dbc))) ([^String collection ^Map ref fields] - (map (fn [x] (from-db-object x true)) (find collection ref fields))) + (with-open [dbc (find collection ref fields)] + (map (fn [x] (from-db-object x true)) dbc))) ([^DB db ^String collection ^Map ref fields] - (map (fn [x] (from-db-object x true)) (find db collection ref fields)))) + (with-open [dbc (find db collection ref fields)] + (map (fn [x] (from-db-object x true)) dbc)))) (defn find-seq "Queries for objects in this collection, returns ISeq of DBObjects." ([^String collection] - (seq (find collection))) + (with-open [dbc (find collection)] + (seq dbc))) ([^String collection ^Map ref] - (seq (find collection ref))) + (with-open [dbc (find collection ref)] + (seq dbc))) ([^String collection ^Map ref fields] - (seq (find collection ref fields))) + (with-open [dbc (find collection ref fields)] + (seq dbc))) ([^DB db ^String collection ^Map ref fields] - (seq (find db collection ref fields)))) + (with-open [dbc (find db collection ref fields)] + (seq dbc)))) ;; ;; monger.collection/find-one From 80a4625d8923953182886f726b765376b98bf319 Mon Sep 17 00:00:00 2001 From: Tom McNulty Date: Thu, 10 Jan 2013 21:01:09 -0700 Subject: [PATCH 2/2] Close Cursor in queries --- src/clojure/monger/query.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/clojure/monger/query.clj b/src/clojure/monger/query.clj index 6ef4392..99233a8 100644 --- a/src/clojure/monger/query.clj +++ b/src/clojure/monger/query.clj @@ -64,12 +64,12 @@ (defn exec [{ :keys [^DBCollection collection query fields skip limit sort batch-size hint snapshot read-preference keywordize-fields options] :or { limit 0 batch-size 256 skip 0 } }] - (let [cursor (doto (.find collection (to-db-object query) (as-field-selector fields)) - (.limit limit) - (.skip skip) - (.sort (to-db-object sort)) - (.batchSize batch-size) - (.hint (to-db-object hint)))] + (with-open [cursor (doto (.find collection (to-db-object query) (as-field-selector fields)) + (.limit limit) + (.skip skip) + (.sort (to-db-object sort)) + (.batchSize batch-size) + (.hint (to-db-object hint)))] (when snapshot (.snapshot cursor)) (when read-preference