fons / cl-mongo

lisp interface to mongo db
fons.github.com/cl-mongo
MIT License
142 stars 31 forks source link

(mongo-reply nil) ? #9

Closed cmoore closed 12 years ago

cmoore commented 12 years ago

Not sure if this is a bug, per se, or something I'm doing wrong.

Queries to mongodb are randomly throwing an error. I haven't dug into the source yet, though I plan on it later this afternoon, so I'm not sure of the significance of 10 below (mongo-reply nil). Perhaps it's an incompatibility with the version of mongo I'm using.

mongodb 2.0.6 cl-mongo: 20120208 (quicklisp current)

(D0A44F0) : 6 (%AREF1 NIL 0) 517 (D0A4518) : 7 (TO-VAL.1 NIL 0 4) 189 (D0A4560) : 8 (OCTET-TO-INT32.1 NIL 0) 45 (D0A4580) : 9 (FUNCALL #'#<(:INTERNAL CL-MONGO::HEADER CL-MONGO::MONGO-REPLY)> NIL) 61 (D0A45A8) : 10 (MONGO-REPLY NIL) 45 (D0A45D8) : 11 (FUNCALL #'#<#<STANDARD-METHOD CL-MONGO:DB.NEXT (STRING INTEGER)>> "users" 0 :MONGO (type-of CL-MONGO:MONGO) [name : G148982 ] {[id : 9F95230E-FF8C-4724-BEC7-BA1C939A3593] [port : 27017] [host : localhost] [db : liaison]} :LIMIT 0) 205 (D0A4628) : 12 (%%CHECK-KEYWORDS #(2 #(:LIMIT :MONGO) #<METHOD-FUNCTION CL-MONGO:DB.NEXT #>) 27347152) 229 (D0A46B8) : 13 (FUNCALL #'#<#<STANDARD-METHOD CL-MONGO:DB.ITER (CONS)>> ((259 455 0 1 8 ...) (#)) :MONGO NIL :LIMIT 0) 261 (D0A4718) : 14 (%%CHECK-KEYWORDS #(1 #(:LIMIT :MONGO) #<METHOD-FUNCTION CL-MONGO:DB.ITER #>) 27347182) 229 (D0A47A0) : 15 (ITER ((259 455 0 1 8 ...) (#)) :MONGO NIL :MAX-PER-CALL 0) 157 (D0A47F0) : 16 (HAS-PREFERENCE "profsearch") 269

Have you or anyone else ever run into this sort of issue? I'll post the relative code in just a second.

cmoore commented 12 years ago

Ugh, my code is terrible. The perils of iterative learning, I guess. I swear some of it is nice to read... no, really.


(defmacro @-m (&rest body)
  `(with-mongo-connection (:db "liaison")
     ,@body))

(defmacro @-q (collection query &optional args)
  `(@-m (docs (iter (db.find ,collection ,query ,@args)))))

(defmacro w/session (&rest body)
  `(progn
     (hunchentoot:start-session)
     (setf (session-max-time hunchentoot:*session*) (* 60 60 24 265))
     ,@body))

(defun u/uid ()
  (w/session
   (session-value :uid)))

(defun has-preference (n)
  (let ((the-user-doc (car (@-q "users" ($ "uid" (u/uid))))))
    (get-element n the-user-doc)))
cmoore commented 12 years ago

When this happens, I get the following in the mongo logs:

Sat Jul 14 22:55:39 [conn63] getMore: cursorid not found liaison.beacon 0

Still poking at things though.

Another interesting thing - from the slime repl:

LIAISON> (mongo-show)

G154877 -> (type-of MONGO) [name : DEFAULT ] {[id : 607A426E-3A2C-4C29-A81A-890F33640FB9] [port : 27017] [host : localhost] [db : liaison]}

G154863 -> (type-of MONGO) [name : G154863 ] {[id : CF1553B3-FB8B-424F-B547-C2C102930063] [port : 27017] [host : localhost] [db : liaison]}

DEFAULT -> (type-of MONGO) [name : DEFAULT ] {[id : 2156EE63-D540-4CA8-9DE5-2DDCDB5D78B6] [port : 27017] [host : localhost] [db : liaison]}

NIL

cmoore commented 12 years ago

This was on Clozure 1.8. In SBCL 1.0.55 I can't seem to reproduce it.

fons commented 12 years ago

mmmm. yes cl-mongo will/should open up a temporary connection when you use with-mongo-connection. So that's what G15.. etc refers to. You should have only one DEFAULT connection though !!

cmoore commented 12 years ago

Heh, yea, I kinda figured that. I'm not sure how that happened as I wrap all of my mongo functions with (with-mongo-connection ..). Maybe it's a result of having done something wrong in the repl.

cmoore commented 12 years ago

I haven't seen anything like this since, so I'm going to close this out.