我想使用网络公式来过滤存储在 mongo-db 中的记录。
我的查询函数使用如下过滤器:
(defun models (filter)
(docs (db.find *model-collection*
filter
:limit 1)))
当我在 SBCL 中使用它时,它可以使用以下命令之一检索记录 {"NAME" :"a1"}:
(models ($ "NOM" "a1"))
(models (eval (read-from-string "(kv \"NOM\" \"a1\")")))
(<DOCUMENT> : {
_id : CL-MONGO::BSON-OID ...elements : 14})
现在我添加在 Hunchentoot 中开发的 Web 界面,一个用于查询公式,一个用于显示响应:
(define-easy-handler (test :uri "/test") ()
(with-html-output-to-string (*standard-output* nil :prologue t :indent t)
(:html
(:body
(:h1 "Test")
(:form :action "/test1" :method "post" :id "addform"
(:input :type "text" :name "name" :class "txt")
(:input :type "submit" :class "btn" :value "Submit"))))))
(define-easy-handler (test1 :uri "/test1") (name)
(with-html-output-to-string (*standard-output* nil :prologue t :indent t)
(:html
(:body
(:h1 "My List")
(:p (str (models name)))))))
当我在提交表单中输入以下过滤器时:($ "NAME" "a1"),我在显示页面上收到错误,并且在 SBCL 中出现以下日志:
compiling (DEFINE-EASY-HANDLER (TEST1 :URI ...) ...)
[2015-02-12 15:41:47 [ERROR]] The value #\( is not of type (UNSIGNED-BYTE 8).
17: ((SB-PCL::FAST-METHOD CL-MONGO:DB.FIND (STRING T))
#<unused argument>
#<unused argument>
"mycollection"
"($ \"NOM\" \"a1\")"
:MONGO
NIL
:OPTIONS
0
:SKIP
0
:LIMIT
1
:SELECTOR
NIL)
18: (WEB-TEST::MODELS2 "($ \"NOM\" \"a1\")")
19: (WEB-TEST::TEST1 :NAME NIL)
它在 test1 中尝试了几种预转换,例如:
(:p (str (models (eval (read-from-string name)))))
or (:p (str (models (eval (esc name)))))
但它们都不能正常工作。有人可以建议吗?