当使用karras&;提供字段时,如何在MongoDB中更新文档;clojure?

当使用karras&;提供字段时,如何在MongoDB中更新文档;clojure?,mongodb,clojure,functional-programming,mongodb-java,nosql,Mongodb,Clojure,Functional Programming,Mongodb Java,Nosql,我在MongoDB中有一个集合,我需要更新该集合上的某个文档,当该文档中的某个字段在clojure web应用程序中使用API{a clojure wrapper to the mongo java driver}时 我已经想出了这个解决方案,但是,它没有像我预期的那样工作 (ns addressbook.repository (:use karras.core karras.collection karras.sugar)) (def test-db (collectio

我在MongoDB中有一个集合,我需要更新该集合上的某个文档,当该文档中的某个字段在clojure web应用程序中使用API{a clojure wrapper to the mongo java driver}时

我已经想出了这个解决方案,但是,它没有像我预期的那样工作

(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是我的MongoDB中的数据库,user是我保存一些文档的集合。我需要删除文档,其中:name字段与我传递给delete rec函数的rec map的:name字段相匹配

谢谢。

试试:

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

谢谢,事实上,这是我的错误,但是,应该是eq而不是gte。但是,它也不起作用!你有错误吗?你确定你的where匹配任何东西吗?你可以发布一个更完整的例子,其中也包括插入内容吗?我没有收到任何错误,但该文档没有在数据库集合中删除。Insert函数在那里,它的工作原理与我预期的一样{将rec映射插入数据库}。尝试从定义函数的REPL中发布一个转录本,插入一些数据,然后尝试使用delete rec函数,并测试它是否工作。