diff --git a/src/db.lisp b/src/db.lisp index f76fabd..f87c8ec 100644 --- a/src/db.lisp +++ b/src/db.lisp @@ -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)) diff --git a/src/mongo-syntax.lisp b/src/mongo-syntax.lisp index c1978f0..2be447d 100644 --- a/src/mongo-syntax.lisp +++ b/src/mongo-syntax.lisp @@ -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))) diff --git a/src/packages.lisp b/src/packages.lisp index 82ade25..3ee7363 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -2,6 +2,7 @@ (defpackage #:cl-mongo (:use #:common-lisp #:babel #:uuid #:usocket) + (:nicknames #:mongo) (:export ;; @@ -27,6 +28,7 @@ :mongo-swap :with-mongo-connection :kv + :drop :db.create-collection :db.use @@ -39,7 +41,7 @@ :db.iter :db.iterator :db.stop - :db.delete + :db.delete :db.ensure-index :db.run-command :db.indexes @@ -81,6 +83,8 @@ :$exists :$/ :$not + :$and + :$or :$em :$where :$index diff --git a/src/shell.lisp b/src/shell.lisp index 051cbcd..b39123c 100644 --- a/src/shell.lisp +++ b/src/shell.lisp @@ -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)