Fork me on GitHub
#beginners
<
2017-03-28
>
sb15:03:08

(let [conn (mg/connect)
      db   (mg/get-db conn "monger-test")
      coll "scores"]
  ;; updates score for player "sam" if it exists; creates a new document otherwise
  (mc/update db coll {:player "sam"} {$set {:score 1088}} {:upsert true}))

sb15:03:22

how can I create an upsert function with monger which use two argument?

sb15:03:47

(let [conn (mg/connect)
      db   (mg/get-db conn "monger-test")
      coll "scores"]
  ;; updates score for player "sam" if it exists; creates a new document otherwise
  (mc/update db coll {:player “sam” :hello “hello" } {$set {:score 1088}} {:upsert true}))

sb15:03:52

not works for me

sb15:03:07

I would like to update if player AND hello are exits if not create new document

sb15:03:49

I didn’t find in the documentation how to possible to do

sb15:03:08

Do I need to write a function, which find the documents and with ID update? (maybe here is a more easier solution)

sb15:03:52

Ohh. Sorry. Works, just in repl I used a different database. 😞