Update util.clj
Added few util functions
This commit is contained in:
parent
9f3d192dff
commit
5cb653aec1
1 changed files with 16 additions and 0 deletions
|
|
@ -63,6 +63,22 @@
|
||||||
(defprotocol GetDocumentId
|
(defprotocol GetDocumentId
|
||||||
(get-id [input] "Returns document id"))
|
(get-id [input] "Returns document id"))
|
||||||
|
|
||||||
|
(defn valid-hexa-string?
|
||||||
|
[s]
|
||||||
|
(org.bson.types.ObjectId/isValid s))
|
||||||
|
|
||||||
|
(defn valid-coll-name?
|
||||||
|
[coll]
|
||||||
|
(instance? String coll))
|
||||||
|
|
||||||
|
(defn doc-id->str
|
||||||
|
[doc]
|
||||||
|
(if (contains? doc :_id)
|
||||||
|
(let [id (get-id doc)
|
||||||
|
hexa-string (str id)]
|
||||||
|
(and (valid-hexa-string? hexa-string) (assoc doc :_id hexa-string)))
|
||||||
|
doc))
|
||||||
|
|
||||||
(extend-protocol GetDocumentId
|
(extend-protocol GetDocumentId
|
||||||
DBObject
|
DBObject
|
||||||
(get-id
|
(get-id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue