is there a way to hand in several lines of Javascript to Monger?

22 views
Skip to first unread message

lawrenc...@gmail.com

unread,
May 13, 2013, 2:44:28 PM5/13/13
to clojure...@googlegroups.com

I often have to generate reports -- pulling data out of Mongo, and then adding it up somehow. When I am at the terminal, I sometimes start the mongo shell and generate a report by writing serval lines of Javascript: a find() query, and then maybe a loop that goes over the results and calculates something, perhaps adding and dividing something. 

Is there  a way I can hand in several lines of Javascript code to Monger, with Monger passing it along to Mongo and getting a calculated result? 



Michael Klishin

unread,
May 13, 2013, 2:56:47 PM5/13/13
to Monger, a Clojure MongoDB driver

Is there  a way I can hand in several lines of Javascript code to Monger, with Monger passing it along to Mongo and getting a calculated result? 

The same way you'd pass a JS function with just one line.

Clojure supports multi-line strings:

user> (def s "line one
              line two
              line three")
#'user/s
user> s
"line one\n              line two\n              line three"

Finally, you can use resource files (which is highly recommended). See clojurewerkz.support.js/load-resource
in this example:

--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

Clinton Dreisbach

unread,
May 13, 2013, 3:08:59 PM5/13/13
to clojure...@googlegroups.com
In order to do the same thing, I used Scriptjure
(https://github.com/arohner/scriptjure) to generate JS code from
Clojure code. This was kind of insano and I recommend it only if you
are nuts and/or have to turn a Clojure data structure into a
map/reduce command for MongoDB.
> --
> Documentation: http://clojuremongodb.info
> Issues: https://github.com/michaelklishin/monger/issues
>
> More Clojure libraries: http://clojurewerkz.org
> ---
> You received this message because you are subscribed to the Google Groups
> "Monger, a Clojure MongoDB driver" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure-mongo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/clojure-mongodb?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages