Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package nickname and drop operation #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion src/db.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ For most commands you can just uses the key-value shown in the mongo documentati
(assert (not (null collection)))
(db.find "$cmd" (kv (kv "dropIndexes" collection) (kv "index" index)) :mongo mongo))

(defmethod db.run-command ((cmd (eql :drop)) &key (mongo (mongo)) (collection nil) (index "*"))
(defmethod db.run-command ((cmd (eql :drop)) &key (mongo (mongo))
(collection nil)
(index "*"))
(assert (not (null collection)))
(db.find "$cmd" (kv->ht (kv "drop" collection)) :mongo mongo))

Expand Down
15 changes: 15 additions & 0 deletions src/mongo-syntax.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@
(defmacro $size (&rest args)
`($op "$size" ,@args))

(defmacro $or (&rest args)
(let ((size (length args))
(arr (gensym)))
`(let ((,arr (make-bson-array :size ,size)))
,@(loop for arg in args
collect `(bson-array-push ,arg ,arr))
(kv "$or" ,arr))))

(defmacro $and (&rest args)
(let ((size (length args))
(arr (gensym)))
`(let ((,arr (make-bson-array :size ,size)))
,@(loop for arg in args
collect `(bson-array-push ,arg ,arr))
(kv "$and" ,arr))))

(defun empty-str(str)
(if (and str (zerop (length str)))
Expand Down
6 changes: 5 additions & 1 deletion src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(defpackage #:cl-mongo
(:use #:common-lisp #:babel #:uuid #:usocket)
(:nicknames #:mongo)
(:export

;;
Expand All @@ -27,6 +28,7 @@
:mongo-swap
:with-mongo-connection
:kv
:drop

:db.create-collection
:db.use
Expand All @@ -39,7 +41,7 @@
:db.iter
:db.iterator
:db.stop
:db.delete
:db.delete
:db.ensure-index
:db.run-command
:db.indexes
Expand Down Expand Up @@ -81,6 +83,8 @@
:$exists
:$/
:$not
:$and
:$or
:$em
:$where
:$index
Expand Down
3 changes: 3 additions & 0 deletions src/shell.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ which deletes all documents in foo, with field key equal to 1."
((zerop line))
(delete-docs))))

(defun drop (collection &key (mongo (mongo)))
(db.run-command "drop" :arg collection))

(defvar *indent*)

(defun new-line (stream)
Expand Down