开发者

How to update a Document in MongoDB when a field is given with karras & clojure?

I have a Collection in MongoDB, I need to update a certain Documents on that, when a field is given in that Document with karras API {A clojure wrapper to the mongo java driver } in clojure web application?

I've come up with this solution, but, it's not working as I expect.

(ns addressbook.repository
  (:use karras.core
    karras.collection
    karras.sugar))

(def test-db (collection (connect) :mydb :user))

(defn no-of-docs []
  (count-docs test-db))


(defn insert-rec [rec]
  (insert test-db rec))

(defn fetch-rec []
  (fetch-all test-db))

(defn filter-db [data]
  (map #(dissoc % :_id) data))

(defn delete-rec [rec]
  (delete test-db (where (eq (str (:name rec)) (str :name)))))

mydb is the Database in my MongoDB, and user is the Collection on which I saves some Documents. I need to delete the Document where :name field m开发者_JAVA百科atches with the rec map's :name field which I passed to that delete-rec function.

Thanks.


Try:

(delete test-db (where (eq :name (:name rec))))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜