Server side Javascript

MongoDB is using Javascript for server side scripts.
Clojurescript compiles to Javascript,and it can be used to replace Javascript.

Javascript is used in 2 ways in MongoDB

  1. functions,without dependencies ,for example $function $accumulator operators
  2. javascript with dependencies , for example MongoDB Atlas triggers


  • compiles to javascript
  • has many features like immutable data structures etc
  • very fast

We can use Clojurescript in MongoDB,but not in places where we need 1 Javascript function without dependencies.

The reason is its big language to wrap inside 1 function,its like loading all the language in each call,and its slow.

Functions,without dependencies

cMQL provide 3 things

  1. allows functions to have function dependencies (useful from wrappers,and wisp)
    (so we avoid code repetetion,and slow code)
  2. generates 1 js functions,from nested $function calls (usefull fro cMQL wrappers) (if we nest like 5 js calls,MongoDB will run only 1,for perfomance reasons)
  3. compiles wisp to js

cMQL wrappers

We can wrap small js functions,under cMQL(Clojure functions).
And then we can combine them.

Clojurescript like languages

There are Clojurescript like languages that are smaller,and closer to javascript.
They look like a clojure-way to use Javascript.

We need a language that looks like Clojurescript but it produces small code, and uses Javascript data.

One language that does exactly this is Wisp
cMQL is using wisp to generate smaller Javascript functions.

For example this is wisp code (wisp looks like Clojure), but for example [] is not a vector its a javascript array.

(defn myloop [n]
(loop [n n]
(if (= n 0)
[{"a" "b"},3,"astring"]
(recur (dec n)))))

And the wisp compiler produces js code

function myloop(n) {
return function loop() {
var recur = loop;
var nø2 = n;
do {
recur = isEqual(nø2, 0) ? [
{ 'a': 'b' },
] : (loop[0] = dec(nø2), loop);
} while (nø2 = loop[0], recur === loop);
return recur;

Javascript with dependencies