Skip to content

Commit

Permalink
Don't coerce the id arg of fetch-by-id to an ObjectID, since that is …
Browse files Browse the repository at this point in the history
…overly restrictive
  • Loading branch information
purcell committed Nov 3, 2010
1 parent f4b2908 commit 29341e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/somnium/congomongo.clj
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions test/congomongo_test.clj
Expand Up @@ -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
Expand Down

0 comments on commit 29341e0

Please sign in to comment.