EzDevInfo.com

monger

Monger is an idiomatic Clojure MongoDB driver for a more civilized age: with sane defaults, batteries included, well documented, very fast Monger, a MongoDB Clojure client for a more civilized age | MongoDB library for Clojure

Clojure convert {"a.b" 1, "a.c" 2, "d.e" 3} to {:a {:b 1, :c 2}, :d {:e 3}} (for compojure/hiccup with monger hierarchy)

My mongodb schema has a JSON hierarchy to it. When I get the field params from compojure, the hash is in flat dotted notation like {"a.b" 1, "a.c" 2, "d.e" 3}. I'm wanting to use monger to insert the data, but that expects a real hierarchical format like {:a {:b 1, :c 2}, :d {:e 3}}. Is there any way to automatically convert from one to the other?


Source: (StackOverflow)

Return updated document with Monger

In Monger there is a insert-and-return function for returning a newly inserted document.

There is no update-and-return function.

How can I return an updated document from the function that executes the update?

I think I could use save-and-return but it seems to me that I am not able to use operators like $push with this function.


Source: (StackOverflow)

Advertisements

java.lang.RuntimeException: java.lang.NoSuchMethodError: when running clojure web app

I'm trying to run a small Clojure web app I wrote, and I'm getting an exception from lein ring server that isn't giving me any useful information. I've googled the error and found this discussion, which suggested running lein deps :tree to route out the problem, but that's been depreciated.

Full stack trace:

Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.RT.mapUniqueKeys([Ljava/lang/Object;)Lclojure/lang/IPersistentMap;
    at clojure.lang.Util.runtimeException(Util.java:165)
    at clojure.lang.Compiler.eval(Compiler.java:6476)
    at clojure.lang.Compiler.eval(Compiler.java:6455)
    at clojure.lang.Compiler.load(Compiler.java:6902)
    at clojure.lang.RT.loadResourceScript(RT.java:357)
    at clojure.lang.RT.loadResourceScript(RT.java:348)
    at clojure.lang.RT.load(RT.java:427)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5275)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$require.doInvoke(core.clj:5352)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at monger.collection$eval698$loading__4505__auto____699.invoke(collection.clj:12)
    at monger.collection$eval698.invoke(collection.clj:12)
    at clojure.lang.Compiler.eval(Compiler.java:6465)
    at clojure.lang.Compiler.eval(Compiler.java:6455)
    at clojure.lang.Compiler.load(Compiler.java:6902)
    at clojure.lang.RT.loadResourceScript(RT.java:357)
    at clojure.lang.RT.loadResourceScript(RT.java:348)
    at clojure.lang.RT.load(RT.java:427)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5271)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$require.doInvoke(core.clj:5352)
    at clojure.lang.RestFn.invoke(RestFn.java:457)
    at donebox.views.landing$eval692$loading__4505__auto____693.invoke(landing.clj:1)
    at donebox.views.landing$eval692.invoke(landing.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6465)
    at clojure.lang.Compiler.eval(Compiler.java:6455)
    at clojure.lang.Compiler.load(Compiler.java:6902)
    at clojure.lang.RT.loadResourceScript(RT.java:357)
    at clojure.lang.RT.loadResourceScript(RT.java:348)
    at clojure.lang.RT.load(RT.java:427)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5271)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:604)
    at clojure.core$use.doInvoke(core.clj:5363)
    at clojure.lang.RestFn.invoke(RestFn.java:457)
    at donebox.core$eval686$loading__4505__auto____687.invoke(core.clj:1)
    at donebox.core$eval686.invoke(core.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6465)
    at clojure.lang.Compiler.eval(Compiler.java:6455)
    at clojure.lang.Compiler.load(Compiler.java:6902)
    at clojure.lang.RT.loadResourceScript(RT.java:357)
    at clojure.lang.RT.loadResourceScript(RT.java:348)
    at clojure.lang.RT.load(RT.java:427)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5271)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$require.doInvoke(core.clj:5352)
    at clojure.lang.RestFn.invoke(RestFn.java:457)
    at user$eval3.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:6465)
    at clojure.lang.Compiler.eval(Compiler.java:6454)
    at clojure.lang.Compiler.eval(Compiler.java:6431)
    at clojure.core$eval.invoke(core.clj:2795)
    at clojure.main$eval_opt.invoke(main.clj:296)
    at clojure.main$initialize.invoke(main.clj:315)
    at clojure.main$null_opt.invoke(main.clj:348)
    at clojure.main$main.doInvoke(main.clj:426)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:405)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:518)
    at clojure.main.main(main.java:37)
Caused by: java.lang.NoSuchMethodError: clojure.lang.RT.mapUniqueKeys([Ljava/lang/Object;)Lclojure/lang/IPersistentMap;
    at monger.conversion$loading__4910__auto__.invoke(conversion.clj:24)
    at monger.conversion__init.load(Unknown Source)
    at monger.conversion__init.<clinit>(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:266)
    at clojure.lang.RT.loadClassForName(RT.java:2030)
    at clojure.lang.RT.load(RT.java:417)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5271)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:604)
    at clojure.core$use.doInvoke(core.clj:5363)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at monger.core$eval704$loading__4505__auto____705.invoke(core.clj:10)
    at monger.core$eval704.invoke(core.clj:10)
    at clojure.lang.Compiler.eval(Compiler.java:6465)
    ... 95 more
Subprocess failed

project.clj:

(defproject donebox "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :source-paths ["src/main/clj"]
  :java-source-paths ["src/main/java"] ; Java source is stored separately.
  :test-paths ["test" "src/test/clojure"]
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [ring "1.2.0-RC1"]
                 [ring/ring-servlet "1.2.0-RC1"]
                 [compojure "1.1.5"]
                 [hiccup "1.0.3"]
                 [com.novemberain/monger "1.5.0"]
                 [org.clojure/data.xml "0.0.7"]
                 [org.clojure/data.json "0.2.2"]
                 [clj-oauth "1.4.0"]
                 [clojure-twitter "1.2.5"]
                 [ring-anti-forgery "0.2.1"]]
  :plugins [[lein-ring "0.8.5"]
            [lein-cljsbuild "0.3.2"]]
  :ring {:handler donebox.core/handler :init donebox.core/mongo-config :destroy donebox.core/disconnect}
  :cljsbuild {
    :builds [{
        ; The path to the top-level ClojureScript source directory:
        :source-paths ["src/main/cljs"]
        ; The standard ClojureScript compiler options:
        ; (See the ClojureScript compiler documentation for details.)
        :compiler {
          :output-to "resources/public/js/main.js"  ; default: target/cljsbuild-main.js
          :optimizations :advanced
          :pretty-print true}}]})

core.clj:

(ns donebox.core
  (:use [compojure.core]
        [donebox.views.landing]
        [ring.middleware.params]
        [ring.middleware.anti-forgery])
  (:require [compojure.route :as route]
            [compojure.handler :as handler]
            [compojure.response :as response]
            [monger.core :as mg])) ;; Error here.

(defroutes main-routes
  (GET "/" [] (index))
  (POST "/process_index" [] (handle-index))
  (GET "/thankyou" [] (thankyou))
  (GET "/roadmap" [] (roadmap))
  (route/resources "/")
  (route/not-found "Page not found"))

(def handler
  (-> (handler/site main-routes)
      (wrap-params)
      (wrap-anti-forgery)))

(defn mongo-config []
  ((mg/connect-via-uri! "mongodb://<dbuser>:<dbpwd>@ds031628.mongolab.com:31628/donebox"))

(defn disconnect []
  (mg/disconnect!))

Is there any information on what I can do about this exception? Thank you for your time and consideration.


Source: (StackOverflow)

Mapping Mongodb ObjectId to and from string automatically

I am accessing Mongo database from Clojure using Monger library. One thing that annoys me is switching back and forth between ObjectId instances and strings.

For example, the this code (mc/find-maps "posts" {}) will evaluate to maps with the value of _id entry set to instances of ObjectId class, while in my app I find it more useful to simply have it as a string for which I know that it is unique.

On the other hand for expressions like: (mc/find-map-by-id "posts" (new ObjectId id)) where I do use a String object for the id parameter, I have to use it to construct an instance of ObjectId.

Is there a way to make the values of _id convert between Strings in the application and ObjectId on the mongo side automatically and transparently? Some kind of option that, when enabled, creates maps with string representations of ids, and vice versa converts string representations of ids t object ids when used as parameters in queries?

If not, what other strategies are available?


Source: (StackOverflow)

Read-only connection to a slave instance using monger

I have a replica set and I want to establish standalone read-only connection to a slave instance.

Normally, I should experience no problems doing it. The only thing I ought to do is to set slaveOk=true to be able to query it with read operations. It works great when I'm using nodejs or mongo console, but I found no way to do it using monger.

The strangest thing is that I'm getting an exception when I'm calling set-db! function:

MongoException not talking to master and retries used up com.mongodb.DBTCPConnector.innerCall (DBTCPConnector.java:314)

Establishing replica-set connection is not an option for me.

Currently I'm using [com.novemberain/monger "1.4.0"].

Thanks!


Update: I looked through Java MongoDB Driver API Documentation and found slaveOk method. I wrote the following code, hoping it'll work:

(defn slave-connect!
  [& args]
  (mg/set-connection!
    (doto (apply mg/connect args)
          (.slaveOk))))

But all I've got is a new exception:

MongoException not master com.mongodb.CommandResult.getException (CommandResult.java:100)


Source: (StackOverflow)

Lazy evaluation with compare-and-set

I'm trying to implement a get-database function that retrieves the database reference from Monger the first time it is called, remembers the value in an atom and returns it directly on subsequent calls. My current code looks like this:

(def database (atom nil))

(defn get-database
  []
  (compare-and-set! database nil
    (let [db (:db (mg/connect-via-uri (System/getenv "MONGOLAB_URI")))] db))
  @database)

The problem is that the let clause seems to be evaluated even if compare-and-set! returns false (i.e. database is not nil). Is there some way to get this to evaluate lazily so I don't incur the penalty of retrieving the Monger connection, or is this approach fundamentally misguided?


Source: (StackOverflow)

Clojure <-> Monger <-> MongoDB: reading and writing a set

I'm using Monger to store data in MongoDB. I would like to store a Clojure set. Reading and writing the set does work, but it is returned as a list. I suspect MongoDB doesn't actually support the set data type, so the Monger client doesn't either, but hopefully I'm wrong.

Is there some way to have Monger return the set I stored with the correct type?

Minimal Leiningen example is below (which is just the most basic Monger example):

> lein new mongo-test
> cd mongo-test

Edit project.clj to add Monger dependency:

(defproject mongo-test "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [com.novemberain/monger "2.0.0-rc1"]])

Start the REPL:

> lein repl

Insert and read back a set - note the found value is a list, not a set:

user=> (require '[monger.core :as mg])
nil
user=> (require '[monger.collection :as mc])
nil
user=> (def conn (mg/connect))
#'user/conn
user=> (def db (mg/get-db conn "monger-test"))
#'user/db
user=> (mc/remove db "things")
#<WriteResult { "serverUsed" : "127.0.0.1:27017" , "n" : 1 , "connectionId" : 248 , "err" :  null  , "ok" : 1.0}>
user=> (mc/insert db "things" {:set #{"A" 1}})
#<WriteResult { "serverUsed" : "127.0.0.1:27017" , "n" : 0 , "connectionId" : 248 , "err" :  null  , "ok" : 1.0}>
user=> (.next (mc/find db "things"))
{"_id" #<ObjectId 537ce43130045df5b9ff1102>, "set" [1 "A"]}
user=> (get (.next (mc/find db "things")) "set")
[1 "A"]
user=> (type (get (.next (mc/find db "things")) "set"))
com.mongodb.BasicDBList
user=> (set (get (.next (mc/find db "things")) "set"))
#{1 "A"}
user=> (type (set (get (.next (mc/find db "things")) "set")))
clojure.lang.PersistentHashSet

Obviously I can pass the result to set, as in the last two lines, but I don't want to have to call that for each specific key. Is there a way to have this happen transparently?


Source: (StackOverflow)

Monger database connecting and storing the results

So I have a database of posts I want to access, but I also want to cache the results of the query so I'm not making extra connections to the database.

So far I have something like

 ;;talk with the database and get posts by their [count]
 (defn posts-from-db []
   (let [conn (mg/connect {:host "127.0.0.1" :port 27272})
         db (mg/get-db conn "submitted-content")
         coll "posts"]
     (with-collection db coll
     (find {})
     (fields [:post_content :id])
     ;; it is VERY IMPORTANT to use array maps with sort
     (sort (array-map :tags -1 :post_content 1))
     (limit numberOfPosts))))

This returns a collection of results that look like

({:_id #<ObjectId 54d927ce9c521eb276553f11>, :post_content "Mermaids and dakinis "},
 { .... },
 { .... },
 { .... })

I think a good way to do this is to store the result in a symbol (var? key? .. not sure what the appropriate verbiage is for Clojure) and then check if that var is set.

How does a developer normally address this situation?


Source: (StackOverflow)

When using monger, do I need to supply connection each request?

In the documentation, the mongodb connection is established once, before being used without passing the connection to each command, is that the proper way to use monger, or should I pass the database connection to each call?


Source: (StackOverflow)

Query mongo With joda.time.datetime using clojure-monger

I got this error code when tried query obj with {$lte start $gte end}, can u show me some sample of querying with coda.datetime?

IllegalArgumentException can't serialize class org.joda.time.DateTime org.bson.BasicBSONEncoder._putObjectField (BasicBSONEncoder.java:284)

The Func:

(defn data->orders [start end]
  (let [db (mg/get-db conn/mongo-db "db")
        coll "coll"
        formatter (f/formatter "YYYY-MM-dd")]
    (mc/find-maps db coll
                  {:created_at
                   {$gte (f/parse formatter start)
                    $lte (f/parse formatter end)}})))

Source: (StackOverflow)

How do I add a document to mongodb with monger and Clojure?

I have never used MongoDb before, nor have I used Monger before. I am working on a Clojure app. I simply want to be able to add one document, as an upsert. This is some of my code:

(defn convert-data-to-be-persisted [session-data]
  (convert/to-db-object session-data))

(defn persist-data-to-database [converted-document-to-persist]
  (mc/update "timeout_discovery" {:sessions converted-document-to-persist} {} :upsert true))

I am using monger:

http://clojuremongodb.info/

The println and timbre/spy statements I have are printing this data to the terminal output:

in persist-data-to-database: { "serverUsed" : "/127.0.0.1:27017" , "updatedExisting" : false , "upserted" : { "$oid" : "510680444077296acfa67d6b"} , "n" : 1 , "connectionId" : 4 , "err" : null , "ok" : 1.0}

If I log into MongoDb at the command line, it seems the collection remains empty:

db.timeout_discovery.find() { "_id" : ObjectId("51017c5fa86c7bcc3d423c4d"), "timeout" : "discovery" }

There is one document, but it has nothing in it except "timeout" and "discovery".

I looked here to try to figure out what to do, but every variation that I tried failed:

http://clojuremongodb.info/articles/updating.html

This line:

(convert/to-db-object session-data))

returns this document (but I shorten it here, as the original is long, bloated with more of the HTML that you see here):

in get-data-to-be-persisted the document to persist is: { "e6e20a2c-cb46-498c-b2f2-743e2b38b917" : { "itinerary-as-string" : "\n \t\n \t\t

http://www.super.com/mexico/bars/2012-food-drink-award-nominees-best\" class=\"fn given-name url\">2012 Food & Drink award nominees: Best new beer bar

\n \t\t \t\t \n \n Voting is now closed\nSEE RESULTS HERESee more in Restaurants + Bars

\n \t\n \t\n http://www.super.com/mexico/bars/2012-food-drink-award-nominees-best-new-beer-bar\">http://media.super.com/images/100131935/150/113/image.jpg\" /> \n \n \n \t\n \t\t

http://www.super.com/mexico/sex-dating/summer-dates-in-mexico-bars-and-restaurants\" class=\"fn given-name url\">Summer dates : Food-and-drink dates at MEXICO bars and restaurants

\n \t\t \t\t

Sex & dating

\n \n \n dinner or drinks at MEXICO hot spots on these summer dates. If you’re going to woo a food-obsessed partner, go beyond the standard dinner and a movie this season. Check out five food-and-drink-focused summer dates at New York...

\n \t\n \t\n http://www.super.com/mexico/sex-dating/summer-dates\">http://media.super.com/images/100453911/150/113/image.jpg\" /> \n \n \n \t\n \t\t

http://www.super.com/mexico/restaurants/organic\" class=\"fn given-name url\">Organic

\n \t\t \t\t

Food & Drink, American, Asian

\n \n \n \n $\n \n \n \n \n \n https://foursquare.com/intent/venue.html\" data-context=\"vcard-Content-Venue-50137\">Save to foursquare\n \n \n \n Tribeca fro-yo fanatics can satisfy all their wholesome cravings at the second location of this organic health-food bar. The bright takeout shop—outfitted with wood paneling and a white-and-green counter—also serves fresh-squeezed juices and smoothies,...

Edit \n \t \n \t\n \t\n http://www.super.com/mexico/restaurants/organic\">http://media.super.com/images/100461855/150/113/image.jpg\" /> \n \n \n \n \t \n 275 Greenwich St, (between Murray and Warren Sts), New York, 10007\n \t \n \t \t \n \t \tAverage course: $9. AmEx, Disc, MC,... \t \n \n http://www.super.com/mexico/restaurants/organic\">\n \t\t\t\t\t\t\t \t \t \tGet info\n \n \n\t\t " , "username" : "whoandwhy@geocities.com" , "created-at" : "2013-01-28T13:41:53" , "ip-address" : "10.0.1.53" , "cookie-id" : "timeout-kiosk5903266" , "questions-and-answers" : { "what-are-you-interested-in" : [ ":food-and-bars"] , "who-are-you-with" : [ ":adults"] , "what-is-your-email" : "whoandwhy@geocities.com" , "how-long-are-you-in-new-york" : ":two-weeks"}}}

So, why would this not save?

I am not seeing any errors in the terminal output, though if there is an error, I would like suggestions about how to capture it and see it.

If there are no errors, do I simply have the syntax wrong for MongoDb or monger?


Source: (StackOverflow)

Why monger only update one record instead all the records in the list

I have a function that takes in list of entry and save it to mongo using monger. What is strange is that only the one record will be updated and the rest ignored unless I specify multi:true. I don't understand why the multi flag is necessary for monger to persist all the updates to mongodb.

(defn update-entries
   [entries]
   (let [conn (mg/connect)
         db (mg/get-db conn "database")]
     (for [e entries] (mc/update db "posts" {"id" (:id e)} {$set {:data (:data e)}} {:multi true}))))

Source: (StackOverflow)

How to update / insert a MongoDB sub document with Monger?

I'm using Clojure's Monger library to connect to a MongeoDB database.

I want to update, insert & remove subdocuments in my Mongo database. MongoDB's $push modifier lets me do this on the root of the searched document. But I want to be able to $push onto a sub-collection. Looking at Monger's tests, it looks possible. But I want to be sure I can push to the child-collection of the 3rd parent. Can Monger do something like this?


    (mgcol/update mycollection { :my-criteria-key "my-criteria-value" } { $push { "parent.3.child-collection" "fubar" }} ) 

Even better would be the ability to have a $where clause in my $push. Is something like this possible?


    (mgcol/update mycollection 
          { :doc-criteria-key "doc-criteria-value" } 
          { $push 
              { { $where { parent.child.lastname: 'Smith' } } 
              "fubar" } } 
    )

But even on a basic level, when I try the following command in my repl, I get the below error.

  1. The "fubar" database definitely exists

  2. I'm definitely connected to the DB

  3. The { :owner "fubar@gmail.com" } criteria is definitely valid; and

  4. I tried both "content.1.content" and "content.$.content":


    repl => (mc/update "fubar" { :owner "fubar@gmail.com" } { $push { "content.1.content" { "fu" "bar" } } } ) 
    ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB  monger.collection/update (collection.clj:310)
    repl => 
    repl => 
    repl => (clojure.repl/pst *e)
    ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB
            monger.collection/update (collection.clj:310)
            bkell.run.run-ring/eval2254 (NO_SOURCE_FILE:46)
            clojure.lang.Compiler.eval (Compiler.java:6406)
            clojure.lang.Compiler.eval (Compiler.java:6372)
            clojure.core/eval (core.clj:2745)
            clojure.main/repl/read-eval-print--6016 (main.clj:244)
            clojure.main/repl/fn--6021 (main.clj:265)
            clojure.main/repl (main.clj:265)
            user/eval27/acc--3869--auto----30/fn--32 (NO_SOURCE_FILE:1)
            java.lang.Thread.run (Thread.java:619)

Had anyone come across this and solved it?

Thanks


Source: (StackOverflow)

"Shared" Connection on Monger Clojure

I am start with monger today, the docs use examples like this:

(let [conn (mg/connect)
      db   (mg/get-db conn "monger-test")
      coll "documents"]
  (mc/insert db coll {:first_name "John"  :last_name "Lennon"})
  (mc/insert db coll {:first_name "Ringo" :last_name "Starr"})

  (mc/find db coll {:first_name "Ringo"}))

All documentation examples use that structure. Always connect to MongoDB, then use db on mc/insert... . The question is, how I can put this code on a function and use it in my functions that execute mongodb queries, without repeat below code all time:

(let [conn (mg/connect)
          db   (mg/get-db conn "monger-test")
          coll "documents"] ...

Thanks.


Source: (StackOverflow)

Not letting Monger serialize

I'm new to Clojure and I'm having issues with Monger.

I'm trying to user Monger with Friend. I have this ns:

(ns cemerick.friend-demo.users
  (:require [cemerick.friend.credentials :refer (hash-bcrypt)]))

(def users (atom {"friend" {:username "friend"
                            :password (hash-bcrypt "clojure")
                            :pin "1234" ;; only used by multi-factor
                            :roles #{::user}}
                  "friend-admin" {:username "friend-admin"
                                  :password (hash-bcrypt "clojure")
                                  :pin "1234" ;; only used by multi-factor
                                  :roles #{::admin}}
(derive ::admin ::user)

When I try to add this to database using Monger with

(mc/insert "users"  {:username "friend",
                     :password "$2a$10$YGcqRFL67J5NDo7hfkVslerDYc1iIGBy0js871wxnXxOvdvJZ4Aua",
                     :pin "1234",
                     :roles #{:cemerick.friend-demo.users/user}})

Monger serializes #{:cemerick.friend-demo.users/user} as "user" Is there any way to put that value as is or is there any way to change "user" to #{:cemerick.friend-demo.users/user}?


Source: (StackOverflow)