當使用 karras 和 clojure 給出字段時,如何更新 MongoDB 中的文檔? (How to update a Document in MongoDB when a field is given with karras & clojure?)


問題描述

當使用 karras 和 clojure 給出字段時,如何更新 MongoDB 中的文檔? (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 matches with the rec map's :name field which I passed to that delete-rec function.

Thanks.


參考解法

方法 1:

Try:

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

(by Abimaran Kugathasanmac)

參考文件

  1. How to update a Document in MongoDB when a field is given with karras & clojure? (CC BY-SA 3.0/4.0)

#functional-programming #mongodb-java #mongoDB #Clojure #NoSQL






相關問題

有沒有辦法在 C 中進行柯里化? (Is there a way to do currying in C?)

Scala 的產量是多少? (What is Scala's yield?)

功能性 javascript 和網絡瀏覽器 javascript 版本 (Functional javascript and web browser javascript versions)

從元組列表中獲取唯一路徑 (Getting Unique Paths from list of tuple)

用函數作為參數定義函數 (Defining a function with a function as an argument)

如何使用函數 VB.NET 插入數據庫? (How to use Function VB.NET Insert To Database?)

Python中列表的模式匹配 (Pattern matching of lists in Python)

如何在haskell中顯示派生樹? (how can i show a derivation tree in haskell?)

編寫一個可任意調用次數的 curried javascript 函數,該函數在最後一次函數調用時返回一個值 (Writing a curried javascript function that can be called an arbitrary number of times that returns a value on the very last function call)

我應該總是給我的函數一個返回值嗎? (Should I always give a return value to my function?)

如何在 JavaScript 中實現動態回調參數 (How can I achieve dynamic callback arguments in JavaScript)

Haskell 是否有一個函數可以創建將函數應用於列表的每個變體 (Haskell Is there a function for creating every variation of applying a function to a list)







留言討論