Monger: long running queries without timeout exceptions
I just had problems with running long-time queries using monger - mongodb library for clojure without getting cursor timeout exceptions after ~10 minutes.
Here is my current workaround, until my pull-requests with updated interfaces for find-functions gets accepted:
monger.collection/find function returns DBCursor object, which has public method setOptions, that accepts constants from com.mongodb.Bytes class.
 (ns changelogger.db
    (:require [monger.core :as mongo]
                  [monger.collection :as coll]
                  [monger.conversion :refer [from-db-object]]
                  [monger.joda-time])
   (:import [com.mongodb Bytes]))
...
 (defn get-sorted-products 
   "returns lazy-seq of products-map."
   [the-criteria]
   (let [db-cur (coll/find "products" the-criteria)]
     (.setOptions db-cur Bytes/QUERYOPTION_NOTIMEOUT)
     (map #(from-db-object %1 true) db-cur))Valid values for setOptions on mongodb docs
Written by Tim Gluz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Clojure 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#
 
 
 
 
