(* & exprs)
$multiply Multiply numbers Call (* 1 2.3 5)
$multiply Multiply numbers Call (* 1 2.3 5)
(+ & es)
$add Add numbers or numbers(milliseconds) to dates Call (+_ 1 2) (+_ :adate (*_ 5 60 1000))
$add Add numbers or numbers(milliseconds) to dates Call (+_ 1 2) (+_ :adate (*_ 5 60 1000))
(- e-n)
(- e-n & es)
$substract Substract numbers or numbers(milliseconds) to dates Call (- 2 1) (- :adate (*_ 5 60 1000))
$substract Substract numbers or numbers(milliseconds) to dates Call (- 2 1) (- :adate (*_ 5 60 1000))
(= e1 e2 & es)
$eq Check for equality, works on all types
$eq Check for equality, works on all types
(and & es)
$and Logical and,short circuit,false if one false/0/null/undefined
$and Logical and,short circuit,false if one false/0/null/undefined
(assoc array-or-doc index value)
if the index/key is variable,i give it as {:key variable-e} or {:index variable-e}
if the index/key is variable,i give it as {:key variable-e} or {:index variable-e}
(avg group-or-array-e)
(avg e1 e2 & es)
$avg Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Ignores non numeric(doesnt count as members) if all non-numeric returns null Call (avg- e) ; the array is made from group 1e/member (avg- array) (avg- number1 number2 ...)
$avg Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Ignores non numeric(doesnt count as members) if all non-numeric returns null Call (avg- e) ; the array is made from group 1e/member (avg- array) (avg- number1 number2 ...)
(cmp e1 e2)
$cmp Compares value, works on all types Returns 1 if e1>e2 , -1 if e1<e2 , 0 if e1=e2
$cmp Compares value, works on all types Returns 1 if e1>e2 , -1 if e1<e2 , 0 if e1=e2
(cmp-str-icase e1-string e2-string)
$strcasecmp string equality ignore case
$strcasecmp string equality ignore case
(compile-functions f-name & f-names)
Compiles one cljs to one javascript function with the same name. The javascript function code,is saved in js/f-name.js The default location to look for js code
Compiles one cljs to one javascript function with the same name. The javascript function code,is saved in js/f-name.js The default location to look for js code
(concat & e-arrays)
$concatArrays Concatenates arrays to return the concatenated array. If any of the argument is null returns null
$concatArrays Concatenates arrays to return the concatenated array. If any of the argument is null returns null
(cond & args)
$switch Call (cond- cond1 e1 ; cond1=boolean-e cond2 e2 ... :else en)
$switch Call (cond- cond1 e1 ; cond1=boolean-e cond2 e2 ... :else en)
(conj e-array e)
Like $push but implemented with concat- Not O(1) $push works only in group
Like $push but implemented with concat- Not O(1) $push works only in group
(conj-distinct e-array e)
Slow contains?- is not O(1) If order not important,add get distinct after
Slow contains?- is not O(1) If order not important,add get distinct after
(conj-each e)
$push Used only in $group Run 1 time/ member of the group Adds the member at the end of the acc array
$push Used only in $group Run 1 time/ member of the group Adds the member at the end of the acc array
(conj-each-distinct e)
$addToSet Used only in $group Run 1 time/ member of the group Adds new member on the acc array only if not exists already
$addToSet Used only in $group Run 1 time/ member of the group Adds new member on the acc array only if not exists already
(contains? e-array e)
$in True is e is member(not index) of e-array
$in True is e is member(not index) of e-array
(convert input-e e-type & args)
$convert Converts an expression to the type i specify using the type etype = double/string/objectId/bool/timestamp/date/int/long/decimal I can use the string representation of type or the number Call (convert- 1.99999 'bool') (convert- any-e 'bool' {:onError e1} {:onNull e2}) ;; optional
$convert Converts an expression to the type i specify using the type etype = double/string/objectId/bool/timestamp/date/int/long/decimal I can use the string representation of type or the number Call (convert- 1.99999 'bool') (convert- any-e 'bool' {:onError e1} {:onNull e2}) ;; optional
(date-from-string date-str & options)
$dateFromString
$dateFromString
(ejs njs-code)
(ejs f-name f-args & f-code)
Execute the javascript code,calls $function operator Used in 2 ways execute nested js => 1 argument execute code from file or argument => 2 or 3+ arguments
Call 1 argument
No wrappers 1 nested call (no need for njs use ejs with 3+ arguments directly) (ejs (njs f-name f-args f-code))
No wrappers 2 nested call (hard to read,use wrappers instead) (ejs :assoc_j [(njs :assoc_j [:myobject 'akey' 'avalue']) ;; doc after first call (nested) 'akey1' 'avalue1'])
Wrappers (here all functions use njs on their body)(usefull for nested calls) The prefered way,makes it look like regular MongoQL operator
(ejs (dissoc-j (assoc-j (assoc-j :mydoc 'e' 5) 'f' 6) 'f'))
assoc-j or dissoc-j wrapper uses njs (defn assoc-cj [doc k v] (njs :assoc_cj [doc k v]))
Call 2 arguments
Assumes that the js/fname.js already exists so no need for code (ejs :assoc_j [:myobject 'akey' 'avalue']
Call 3+ arguments
If javascript saves the code in js/fname.js If Clojurescript compiles and saves the code in js/fname.js Then execute the code,with $function (if code is given old-code is replaced if js/fname.js already existed)
fname(string/keyword),f-args vector,function-boy(each line can be 1 arg)
Javascript
(ejs :assoc_j [:myobject 'akey' 'avalue'] 'function assoc_j (a,k,v) {' ' a[k]=v; return a;}')
ClojureScript
(ejs :assoc_cj [:myobject 'akey' 'avalue'] '(defn assoc_cj [a k v] (do (aset a k v) a)))
Execute the javascript code,calls $function operator Used in 2 ways execute nested js => 1 argument execute code from file or argument => 2 or 3+ arguments Call 1 argument No wrappers 1 nested call (no need for njs use ejs with 3+ arguments directly) (ejs (njs f-name f-args f-code)) No wrappers 2 nested call (hard to read,use wrappers instead) (ejs :assoc_j [(njs :assoc_j [:myobject 'akey' 'avalue']) ;; doc after first call (nested) 'akey1' 'avalue1']) Wrappers (here all functions use njs on their body)(usefull for nested calls) The prefered way,makes it look like regular MongoQL operator (ejs (dissoc-j (assoc-j (assoc-j :mydoc 'e' 5) 'f' 6) 'f')) assoc-j or dissoc-j wrapper uses njs (defn assoc-cj [doc k v] (njs :assoc_cj [doc k v])) Call 2 arguments Assumes that the js/fname.js already exists so no need for code (ejs :assoc_j [:myobject 'akey' 'avalue'] Call 3+ arguments If javascript saves the code in js/fname.js If Clojurescript compiles and saves the code in js/fname.js Then execute the code,with $function (if code is given old-code is replaced if js/fname.js already existed) fname(string/keyword),f-args vector,function-boy(each line can be 1 arg) Javascript (ejs :assoc_j [:myobject 'akey' 'avalue'] 'function assoc_j (a,k,v) {' ' a[k]=v; return a;}') ClojureScript (ejs :assoc_cj [:myobject 'akey' 'avalue'] '(defn assoc_cj [a k v] (do (aset a k v) a)))
(exists? e)
$type True if field exists (not=_ (type- e) 'missing')
$type True if field exists (not=_ (type- e) 'missing')
(expr aggregation-e)
$expr Converts an aggregate expression to a query expression For example i can use aggregate operators in a match stage Allows us to use aggregate operators instead of query operators
$expr Converts an aggregate expression to a query expression For example i can use aggregate operators in a match stage Allows us to use aggregate operators instead of query operators
(filter cond-fn e-array)
$filter Call (filter (fn [:n.] (> :n. 0)) :myarray)
$filter Call (filter (fn [:n.] (> :n. 0)) :myarray)
(first e-group)
$first Used only in $group Take the first member of the group. Only used at $group(in arrays i use (get- ar 0)) If data were sorted on the keys that i group by i take the smallest else random
$first Used only in $group Take the first member of the group. Only used at $group(in arrays i use (get- ar 0)) If data were sorted on the keys that i group by i take the smallest else random
(fn args body)
fn- like Clojure fn Used only in map/filter/reduce , only as argument Call (fn- [:avar.] ...) ; map/filter 1 arg (fn- [:avar. :bvar.] ...) ; reduce 2 args *if argument is :this. or :value. no let(reduce) and not :as(filter/map) , is used.
Reduce example (reduce (fn [:sum. :n.] (+ :sum. :n.)) [] :myarray)
fn- like Clojure fn Used only in map/filter/reduce , only as argument Call (fn- [:avar.] ...) ; map/filter 1 arg (fn- [:avar. :bvar.] ...) ; reduce 2 args *if argument is :this. or :value. no let(reduce) and not :as(filter/map) , is used. Reduce example (reduce (fn [:sum. :n.] (+ :sum. :n.)) [] :myarray)
(identity e)
returns its argument, useful when we want to use an array as argument
returns its argument, useful when we want to use an array as argument
(if-not e-b e1 e2)
$cond e1 when e-b false Call (if-not e-b e1 e2)
$cond e1 when e-b false Call (if-not e-b e1 e2)
(if-not-value e nill-e)
$ifNull Equivalent with (e nil or e not exist) (if- (not-value?- e) nill-e e)
$ifNull Equivalent with (e nil or e not exist) (if- (not-value?- e) nill-e e)
(index-of e-array e)
(index-of e-array e start)
(index-of e-array e start end)
$indexOfArray Returns the index of the matching member,or -1. I can search in a range only,of the array, for example from index=5 to index=10
$indexOfArray Returns the index of the matching member,or -1. I can search in a range only,of the array, for example from index=5 to index=10
(index-of-in-bytes e-s sub-e-s)
(index-of-in-bytes e-s sub-e-s start)
(index-of-in-bytes e-s sub-e-s start end)
$indexOfBytes UTF-8 byte index of the first occurrence or -1
$indexOfBytes UTF-8 byte index of the first occurrence or -1
(index-of-str e-s sub-e-s)
(index-of-str e-s sub-e-s start)
(index-of-str e-s sub-e-s start end)
$indexOfCP UTF-8 code point index of the first occurrence or -1
$indexOfCP UTF-8 code point index of the first occurrence or -1
(last e-group)
$last Used only in $group Take the last member of the group. Only used at $group(in arrays i use (get- ar (-_ (count- ar) 1))) If data were sorted on the keys that i group by i take the largest else random
$last Used only in $group Take the last member of the group. Only used at $group(in arrays i use (get- ar (-_ (count- ar) 1))) If data were sorted on the keys that i group by i take the largest else random
(let vars body)
$let Allows depended variables => generate minimun nested mongo $let Call (let- [:x- 2 :y- 1 :z- (+_ :y- :x-)] :z-)
$let Allows depended variables => generate minimun nested mongo $let Call (let- [:x- 2 :y- 1 :z- (+_ :y- :x-)] :z-)
(leti vars body)
$let Not usefull,like let- but not allows dependent variables Call (leti- [:v1- e1 :v2- e2] e)
$let Not usefull,like let- but not allows dependent variables Call (leti- [:v1- e1 :v2- e2] e)
(literal e)
$literal Used to show that it represents it self,without special MQL meaning. Call (literal- :a) => will mean a string '$a' not a field reference {$project {:myfield {$literal 1}}} => adds :myfield with value 1
$literal Used to show that it represents it self,without special MQL meaning. Call (literal- :a) => will mean a string '$a' not a field reference {$project {:myfield {$literal 1}}} => adds :myfield with value 1
(map map-fn e-array)
$map Call (map (fn [:n.] (+ :n. 1)) :myarray)
$map Call (map (fn [:n.] (+ :n. 1)) :myarray)
(max group-or-array-e)
(max e1 e2 & es)
$max Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Compares(using $cmp) and returns the max With 1 argument its always group or array, else >1 argument Call (max- e) ; the array is made from group 1e/member (max- array) (max- number1 number2 ...)
$max Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Compares(using $cmp) and returns the max With 1 argument its always group or array, else >1 argument Call (max- e) ; the array is made from group 1e/member (max- array) (max- number1 number2 ...)
(min group-or-array-e)
(min e1 e2 & es)
$min Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Compares(using $cmp) and returns the min Call (min- e) ; the array is made from group 1e/member (min- array) (min- number1 number2 ...)
$min Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Compares(using $cmp) and returns the min Call (min- e) ; the array is made from group 1e/member (min- array) (min- number1 number2 ...)
(njs f-name f-args & f-code)
Makes many nested javascirpt calls,1 javascript function => 1 $function call Its for optimization,and much faster. In MongoDB n nested calls => n $function calls Using njs it can be 1 $function call
Allows wrapping of js code,to make it look like MongoQL/Clojure code. The 3 nested calls will be 1 $function call,and looks like normal aggregation operators. (add 2 key-value pairs to a doc,and remove one)
(ejs (dissoc-j (assoc-j (assoc-j :mydoc 'e' 5) 'f' 6) 'f'))
After finishing with the nesting use ejs to execute the function. Call No wrapper,call it from query (ejs (njs f-name f-args f-code))
Wrapper call it on wrapper defn (here on njs no code is given assumes js/assoc_j.js exists) (defn assoc-j [doc k v] (njs :assoc_j [doc k v]))
Use the wrapper in the query (ejs (assoc-j :mydoc 'akey' 'avalue')
Makes many nested javascirpt calls,1 javascript function => 1 $function call Its for optimization,and much faster. In MongoDB n nested calls => n $function calls Using njs it can be 1 $function call Allows wrapping of js code,to make it look like MongoQL/Clojure code. The 3 nested calls will be 1 $function call,and looks like normal aggregation operators. (add 2 key-value pairs to a doc,and remove one) (ejs (dissoc-j (assoc-j (assoc-j :mydoc 'e' 5) 'f' 6) 'f')) After finishing with the nesting use ejs to execute the function. Call No wrapper,call it from query (ejs (njs f-name f-args f-code)) Wrapper call it on wrapper defn (here on njs no code is given assumes js/assoc_j.js exists) (defn assoc-j [doc k v] (njs :assoc_j [doc k v])) Use the wrapper in the query (ejs (assoc-j :mydoc 'akey' 'avalue')
(not e)
$not Logical not,true if not (false/0/null/undefined)
$not Logical not,true if not (false/0/null/undefined)
(not-disjoint? e-array1 e-array2)
At least 1 common
At least 1 common
(not-exists? e)
True if field missing (=_ (type- e) 'missing')
True if field missing (=_ (type- e) 'missing')
(or & es)
$or Logical or,short circuit,false all false/0/null/undefined
$or Logical or,short circuit,false all false/0/null/undefined
(range end-e-integer)
(range start-e-integer end-e-integer)
(range start-e-integer end-e-integer step-e-integer)
$range Produces array of integers range(start end step) step defaults to 1 start defaults to 0
$range Produces array of integers range(start end step) step defaults to 1 start defaults to 0
(re-find pattern-expression string-s-expression)
(re-find pattern-expression string-s-expression options)
$regexFind
$regexFind
(re-find? pattern-expression string-s-expression)
(re-find? pattern-expression string-s-expression options)
$regexMatch
$regexMatch
(re-seq pattern-expression string-s-expression)
(re-seq pattern-expression string-s-expression options)
$regexFindAll
$regexFindAll
(reduce in-rfn init-e input-e-array)
$reduce Call (reduce- (fn [:sum. :n.] (+ :sum. :n.)) [] :myarray)
$reduce Call (reduce- (fn [:sum. :n.] (+ :sum. :n.)) [] :myarray)
(replace s str-e replacement)
$replaceOne match is string not pattern
$replaceOne match is string not pattern
(replace-all s str-e replacement)
$replaceAll match is string not pattern
$replaceAll match is string not pattern
(reverse e-array)
$reverseArray reverses an array,if null => null
$reverseArray reverses an array,if null => null
(round e-n)
(round e-n place-e-n)
$round e-n integer, double, decimal, or long place-e-n = -20 < e-n < 100 default=0 if missing
$round e-n integer, double, decimal, or long place-e-n = -20 < e-n < 100 default=0 if missing
(split e1-string e2-string)
$split splits on e2-string(no regex) returns array
$split splits on e2-string(no regex) returns array
(stdDevPop group-or-array-e)
(stdDevPop e1 e2 & es)
$stdDevPop
$stdDevPop
(stdDevSamp group-or-array-e)
(stdDevSamp e1 e2 & es)
$stdDevSamp
$stdDevSamp
(str & es-s)
$concat Concatenates any number of strings,if 1 or more null => null
$concat Concatenates any number of strings,if 1 or more null => null
(subs e-s start-e-n)
(subs e-s start-e-n end-e-n)
$substrCP Take the substring,starting from start to end UTF8 indexes Counts in UTF-8 code points,negatives indexes are not allowed Call like Clojure's subs (subs s start) ;; end=string size (subs s start end)
$substrCP Take the substring,starting from start to end UTF8 indexes Counts in UTF-8 code points,negatives indexes are not allowed Call like Clojure's subs (subs s start) ;; end=string size (subs s start end)
(subs-bytes e-s start-e-n end-e-n)
$substrBytes Take the substring,starting from start to end BYTES indexes Counts in BYTES,negatives indexes are not allowed Call like Clojure's subs (subs s start) ;; end=string size (subs s start end)
$substrBytes Take the substring,starting from start to end BYTES indexes Counts in BYTES,negatives indexes are not allowed Call like Clojure's subs (subs s start) ;; end=string size (subs s start end)
(subvec e-array start-e-n)
(subvec e-array start-e-n end-e-n)
uses $slic but works like clojure subvec Call (subvec [1 2 3 4 5 6 7] 2 4) = 3,4 Limit cases start>count => empty array (slice do that alone) Doesn't do circles if index>count,just takes till the end cMQL's take works like slice,see take
uses $slic but works like clojure subvec Call (subvec [1 2 3 4 5 6 7] 2 4) = 3,4 Limit cases start>count => empty array (slice do that alone) Doesn't do circles if index>count,just takes till the end cMQL's take works like slice,see take
(sum group-or-array-e)
(sum e1 e2 & es)
$sum Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Ignores non numeric,if all non-numeric returns 0 Call (sum- e) ; the array is made from group 1e/member (sum- array) (sum- number1 number2 ...)
$sum Can be used in $group $match if inside {$expr ...} $addFields=$set $project=$unset $replaceRoot=$replaceWith Ignores non numeric,if all non-numeric returns 0 Call (sum- e) ; the array is made from group 1e/member (sum- array) (sum- number1 number2 ...)
(take n e-array)
(take start-index n e-array)
$slice works like MQL slice,instead of indexes we give number of elements we want but different argument order
$slice works like MQL slice,instead of indexes we give number of elements we want but different argument order
(take-str n e-str)
(take-str start-index n e-str)
$substrCP works like MQL substrCP, but different argument order
$substrCP works like MQL substrCP, but different argument order
(trim e-string)
(trim e-string trim-e-string)
$trim Deletes the characters ofr trim-e-string from the end and from start Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
$trim Deletes the characters ofr trim-e-string from the end and from start Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
(triml e-string)
(triml e-string trim-e-string)
$ltrim Deletes the characters ofr trim-e-string from the start Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
$ltrim Deletes the characters ofr trim-e-string from the start Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
(trimr e-string)
(trimr e-string trim-e-string)
$rtrim Deletes the characters ofr trim-e-string from the end Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
$rtrim Deletes the characters ofr trim-e-string from the end Character order in trim-e-string is ignored,its char1 or char2 ... and i can have multiple matches.Stop deleting when no match. for example gggddeee ged will reutrn '' delete all chars
(trunc e-n)
(trunc e-n place-e-n)
$trunc e-n integer, double, decimal, or long place-e-n = -20 < e-n < 100 default=0 if missing like round,but just removes,not round
$trunc e-n integer, double, decimal, or long place-e-n = -20 < e-n < 100 default=0 if missing like round,but just removes,not round
(type e)
$type Returns a string representation of the argument type
$type Returns a string representation of the argument type
(ziparray & args)
$zip Arguments are arrays. [[firsts of all arrays] [seconds of all arays] ...] if array not same sizes,the nth values dont added to result at all if useLongestLength (default is false) results = largest array size else results = smaller array size(if i dont have from not added in result) If not useLongestLength i always have elements to add from all arrays. If useLongestLength i give defaults,else defaults = [nil ...] defaults = defaults must have the same size as the number of arrays array that i take elements in order,to add to smaller arrays Call (ziparray- [a1 a2 a3] [b1 b2 b3] [c1 c2 c3]) => [[a1 b1 c1] [a2 b2 c2] [a3 b3 c3]
$zip Arguments are arrays. [[firsts of all arrays] [seconds of all arays] ...] if array not same sizes,the nth values dont added to result at all if useLongestLength (default is false) results = largest array size else results = smaller array size(if i dont have from not added in result) If not useLongestLength i always have elements to add from all arrays. If useLongestLength i give defaults,else defaults = [nil ...] defaults = defaults must have the same size as the number of arrays array that i take elements in order,to add to smaller arrays Call (ziparray- [a1 a2 a3] [b1 b2 b3] [c1 c2 c3]) => [[a1 b1 c1] [a2 b2 c2] [a3 b3 c3]
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close