Add extra arities to several update functions

This commit is contained in:
Michael Klishin 2014-05-11 12:50:15 -04:00
parent 37e8df8300
commit 9752950d82

View file

@ -352,16 +352,18 @@
(monger.collection/update db \"people\" {:first_name \"Yoko\"} {:first_name \"Yoko\" :last_name \"Ono\"} {:upsert true) (monger.collection/update db \"people\" {:first_name \"Yoko\"} {:first_name \"Yoko\" :last_name \"Ono\"} {:upsert true)
By default :upsert and :multi are false." By default :upsert and :multi are false."
[^DB db ^String coll ^Map conditions ^Map document {:keys [upsert multi write-concern] ([^DB db ^String coll ^Map conditions ^Map document]
:or {upsert false (update db coll conditions document {}))
multi false ([^DB db ^String coll ^Map conditions ^Map document {:keys [upsert multi write-concern]
write-concern monger.core/*mongodb-write-concern*}}] :or {upsert false
(.update (.getCollection db (name coll)) multi false
(to-db-object conditions) write-concern monger.core/*mongodb-write-concern*}}]
(to-db-object document) (.update (.getCollection db (name coll))
upsert (to-db-object conditions)
multi (to-db-object document)
write-concern)) upsert
multi
write-concern)))
(defn ^WriteResult upsert (defn ^WriteResult upsert
"Performs an upsert. "Performs an upsert.
@ -370,23 +372,27 @@
sets :upsert to true. sets :upsert to true.
See monger.collection/update documentation" See monger.collection/update documentation"
[^DB db ^String coll ^Map conditions ^Map document {:keys [multi write-concern] ([^DB db ^String coll ^Map conditions ^Map document]
:or {multi false (upsert db coll conditions document {}))
write-concern monger.core/*mongodb-write-concern*}}] ([^DB db ^String coll ^Map conditions ^Map document {:keys [multi write-concern]
(update db coll conditions document {:multi multi :write-concern write-concern :upsert true})) :or {multi false
write-concern monger.core/*mongodb-write-concern*}}]
(update db coll conditions document {:multi multi :write-concern write-concern :upsert true})))
(defn ^WriteResult update-by-id (defn ^WriteResult update-by-id
"Update a document with given id" "Update a document with given id"
[^DB db ^String coll id ^Map document {:keys [upsert write-concern] ([^DB db ^String coll id ^Map document]
:or {upsert false (update-by-id db coll id document {}))
write-concern monger.core/*mongodb-write-concern*}}] ([^DB db ^String coll id ^Map document {:keys [upsert write-concern]
(check-not-nil! id "id must not be nil") :or {upsert false
(.update (.getCollection db (name coll)) write-concern monger.core/*mongodb-write-concern*}}]
(to-db-object {:_id id}) (check-not-nil! id "id must not be nil")
(to-db-object document) (.update (.getCollection db (name coll))
upsert (to-db-object {:_id id})
false (to-db-object document)
write-concern)) upsert
false
write-concern)))
;; monger.collection/save ;; monger.collection/save