cMQL use cases

cMQL can be used

  1. as tool without any clojure knowledge
  2. for queries with minumun clojure knowledge mostly the interop above
  3. for queries and some application logic
  4. or even all application in Clojure/cMQL

The first requires no clojure knowledge is required see this
For the second third only basic clojure is needed, and the bellow can help.

If the 2,3,4 approach is used, we need a cMQL app that we will call to query MongoDB.
Clojure as a hosted language makes the call and data return easy for us.



If we use Intellij Idea and Cursive we dont need this step for now,but sooner or later we will need to have Clojure,and its very easy to install it (but you can skip it for now)

Install Clojure


Again if we have cursive,we dont need this step,to run a Clojure app from the IDE,but we will need it anyways so we install it, its very easy to be installed

Install leiningen We download a script,make it executable and when it runs it installed leiningen we need it to use lein install,and install the dependency

Three basic leningen usages are (run then inside the project folder)

  • lein new aprojectName => creates a hello world Clojure project
  • lein repl => start a clojure repl
  • lein uberjar => creates a standalone jar
  • lein install => install the jar as maven dependency,to be used from Clojure/Java projects


There are various IDE's that we can use with plugins for Clojure.

One popular example is Intellij Idea with Cursive plugin

  1. Install Intellij Idea
  2. Install cursive as plugin to Intellij Idea
    go to plugins,and in market place and search for cursive
    it provides a free Non-Commercial licence

*you can change the IDE later if needed see also

Create a Clojure project

  • go to Ideaprojects folder
  • use leiningen and type
  • lein new myproject

Open a Clojure project(for example the project you made or the cmql clojureapp with the examples)

  • File/new/Project from Existing resources
  • select leiningein as build tool

Cursive basic usage

  • It uses paredit,so parenthensis are handled easily
    paredit is strict, we can use comments ; to edit freely
  • ctrl+w to select clojure forms
  • for special symbols like let,a special spacing syntax,to make the cMQL if- for example share this special spacing do.
    • right click on the function name the if-
    • show context actions
    • resolve like, and we see many options

Run a Clojure project/namespace

  • run the namespace,ctrl+shift+f10/shift+f10
  • run with leiningen, run/edit cofigurations and select run with leiningen
    use this is something doesn't work

Install cmql-core

Use the dependencies from clojars

  • [org.cmql/cmql-core "0.1.0-SNAPSHOT"]

Or lein install using the source code on github. Install cmql that is the core that both cMQL-j and cMQL-js require

cd cmql-core
lein install

Java/Clojure programmers

Use the dependencies from clojars

  • [org.cmql/cmql-core "0.1.0-SNAPSHOT"]
  • [org.cmql/cmql-j "0.1.0-SNAPSHOT"]

Or lein install using the source code on github.

cd cmql-j
lein install

Javascript/Clojurescript programmers

Use the dependencies from clojars

  • [org.cmql/cmql-core "0.1.0-SNAPSHOT"]
  • [org.cmql/cmql-js "0.1.0-SNAPSHOT"]

Or lein install using the source code on github.

cd cmql-js
lein install

Java Interop

Call Java from Clojure

  1. New instance => (ClassName. arg1 arg2 ...)
  2. Object method => (.methodName object arg1 arg2 ...)
  3. Field => (.fieldName object)
  4. Static method => (ClassName/staticMethod arg1 arg2 ...)
  5. ClassName/FIELD => ClassName/FIELD

For example

(.toUpperCase "fred") ;;method
(Math/pi) ;;static method
(MyClass. arg1 arg2) ;;create instance

Call Clojure from Java

  1. Clojure programmer makes a normal Java class from Clojure code
    Java programmer can call its methods as normal Java static methods
  2. Java programmer makes a java static function as a wrapper to clojure function and then we call like a normal java function

In the JavaMavenApp both approaches have being used. To see how it works see how to use the JavaMavenApp

JS Interop

Call Javascript from Clojurescript


Call Clojuresript from Javascript

Clojurescript functions are normal js functions so no interop is needed

Basic Clojure

Clojure is easy to learn, the tree syntax can be a new thing, but for data processing this syntax helps alot.
If someone likes data processing, its very likely to like also functional programming.

Tutorials, examples


Books to learn Clojure

There are many Clojure and Clojurescript books.

Resources tools,libraries,websites etc