From 29341e0ae23b8df11d2492a3948a12ebe97f2d9f Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 3 Nov 2010 19:50:00 +0000 Subject: [PATCH] Don't coerce the id arg of fetch-by-id to an ObjectID, since that is overly restrictive --- src/somnium/congomongo.clj | 3 +-- test/congomongo_test.clj | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/somnium/congomongo.clj b/src/somnium/congomongo.clj index bc840f3..c7ce710 100755 --- a/src/somnium/congomongo.clj +++ b/src/somnium/congomongo.clj @@ -169,8 +169,7 @@ When with-mongo and set-connection! interact, last one wins" ;; add fetch-by-id fn (defn fetch-by-id [col id & options] - (let [id (if (instance? ObjectId id) id (object-id id))] - (apply fetch col (concat options [:one? true :where {:_id id}])))) + (apply fetch col (concat options [:one? true :where {:_id id}]))) (defunk distinct-values "Queries a collection for the distinct values of a given key. diff --git a/test/congomongo_test.clj b/test/congomongo_test.clj index 9f6d701..36e7ab0 100755 --- a/test/congomongo_test.clj +++ b/test/congomongo_test.clj @@ -68,6 +68,12 @@ (is (= (map :x (fetch :points :sort {:x 1})) (sort unsorted))) (is (= (map :x (fetch :points :sort {:x -1})) (reverse (sort unsorted))))))) +(deftest fetch-by-id-of-any-type + (with-test-mongo + (insert! :by-id {:_id "Blarney" :val "Stone"}) + (insert! :by-id {:_id 300 :val "warriors"}) + (is (= "Stone" (:val (fetch-by-id :by-id "Blarney")))) + (is (= "warriors" (:val (fetch-by-id :by-id 300)))))) `(deftest databases-test (with-test-mongo