Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/document.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ the document was generated by the client (as opposed to having been read from th
(multiple-value-bind (exists-p key value) (iterator)
(when exists-p (add-element key value doc)))))
doc)))

(defun document->ht (doc/docs)
"Convert a document to a hash-table, recursively."
(cond
((equal (type-of doc/docs) 'document)
(let* ((ht (slot-value doc/docs 'cl-mongo::elements))
(keys (hash-table-keys ht)))
(dolist (x keys)
(sethash x (document->ht (gethash x ht)) ht))
ht))
((listp doc/docs)
(mapcar #'document->ht doc/docs))
((equal (type-of doc/docs) 'cl-mongo::bson-time)
(bson-time-to-ut doc/docs))
(t doc/docs)))

(defmacro sethash(key value hash-table)
`(setf (gethash ,key ,hash-table) ,value))

(defun ht->document.1 (ht)
(multiple-value-bind (oid oid-supplied) (gethash "_id" ht)
Expand Down
1 change: 1 addition & 0 deletions src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:collect-all-elements
:rm-element
:ht->document
:document->ht
:mapdoc
:doc-id
:get-keys
Expand Down