New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mingo

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mingo - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

dist/mingo.es6.js

5

CHANGELOG.md
Changelog
=========
## 1.3.0 / 2017-07-23
- Support ES6 modules
- Fix matching null and missing values. https://github.com/kofrasa/mingo/issues/54
- Improve comparing user-defined types
## v1.2.0 / 2017-07-17

@@ -5,0 +10,0 @@ - Fix `$where` operator not executed last. https://github.com/kofrasa/mingo/pull/50

10

dist/mingo.min.js

@@ -1,3 +0,7 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.Mingo=n.Mingo||{})}(this,function(n){"use strict";function t(){return{isArray:s,isBoolean:o,isDate:h,isEmpty:x,isEqual:q,isFunction:p,isNil:d,isNull:g,isNumber:l,isObject:c,isObjectLike:f,isRegExp:v,isString:a,isUndefined:$}}function r(n,t){_(n)&&N(t)}function e(n){return r(!$(n))}function u(n){switch(w(n)){case"array":return n.map(u);case"object":return A(n,u);default:return n}}function i(n,t){return w(n)===t}function o(n){return i(n,"boolean")}function a(n){return i(n,"string")}function l(n){return i(n,"number")}function s(n){return i(n,"array")}function c(n){return i(n,"object")}function f(n){return n===Object(n)}function h(n){return i(n,"date")}function v(n,t){return i(n,"regexp")}function p(n,t){return i(n,"function")}function d(n){return g(n)||$(n)}function g(n){return i(n,"null")}function $(n){return i(n,"undefined")}function m(n,t){return n.includes(t)}function y(n,t){return!n.includes(t)}function b(n){return!!n}function _(n){return!n}function x(n){return d(n)||s(n)&&0===n.length||c(n)&&0===M(n).length||!n}function O(n){return s(n)?n:[n]}function w(n){return an.toString.call(n).match(/\s(\w+)/)[1].toLowerCase()}function j(n,t){return an.hasOwnProperty.call(n,t)}function N(n){throw new Error(n)}function M(n){return Object.keys(n)}function k(n,t,e){if(r(n===Object(n),"Cannot iterate over object of type '"+w(n)+"'"),s(n))for(var u=0,i=n.length;i>u;u++)t.call(e,n[u],u);else for(var o in n)j(n,o)&&t.call(e,n[o],o)}function A(n,t,r){if(s(n))return n.map(t,r);if(c(n)){for(var e,u={},i=M(n),o=0,a=i.length;a>o;o++)e=i[o],u[e]=t.call(r,n[e],e);return u}N("Input must be an Array or Object type")}function E(n,t){return n.filter(m.bind(null,t))}function I(n,t){var r=[];return F(r,n),F(r,t.filter(y.bind(null,n))),r}function q(n,t){if(n===t)return!0;var r=w(n);if(r!==w(t))return!1;if("number"===r&&isNaN(n)&&isNaN(t))return!0;if(m(["date","regexp"],r))return n.toString()===t.toString();var e,u;if("array"===r){if(n.length===t.length&&0===n.length)return!0;if(n.length!==t.length)return!1;for(e=0,u=n.length;u>e;e++)if(!q(n[e],t[e]))return!1}else{if(![n,t].every(c))return!1;var i=M(n),o=M(t);if(i.length!==o.length)return!1;if(i.sort(),o.sort(),!q(i,o))return!1;for(e=0,u=i.length;u>e;e++){var a=i[e];if(!q(n[a],t[a]))return!1}}return!0}function C(n){var t={},r=[];return k(n,function(n){var e=P(n);j(t,e)||(r.push(n),t[e]=0)}),r}function S(n){return JSON.stringify({"":n})+w(n)+n}function P(n){var t,r,e,u=0,i=S(n);if(0===i.length)return u;for(t=0,e=i.length;e>t;t++)r=i.charCodeAt(t),u=(u<<5)-u+r,u|=0;return u.toString()}function T(n,t,e){for(var u={},i=[],o=n.length,a=[],l=0;o>l;l++){var s=n[l],c=t.call(e,s,l);if(d(c))a.push(s);else{var f=P(s);j(u,f)||(u[f]=[c,l]),i.push(s)}}return i.sort(function(n,t){var r=u[P(n)],e=u[P(t)];return r[0]<e[0]?-1:r[0]>e[0]?1:r[1]<e[1]?-1:r[1]>e[1]?1:0}),F(a,i),r(a.length===n.length,"sortBy must retain collection length"),a}function D(n,t,e){var u={keys:[],groups:[]},i={};return k(n,function(n){var r=t.call(e,n),o=P(r),a=-1;$(i[o])&&(a=u.keys.length,i[o]=a,u.keys.push(r),u.groups.push([])),a=i[o],u.groups[a].push(n)}),r(u.keys.length===u.groups.length,"Cardinality must be equal for groups and keys"),u}function F(n,t){on.push.apply(n,t)}function Q(n){var t=n.dataset.reduce(function(n,t){return n+t},0),r=n.dataset.length||1,e=n.sampled===!0?1:0,u=t/(r-e);return Math.sqrt(n.dataset.reduce(function(n,t){return n+Math.pow(t-u,2)},0)/r)}function R(n,t){for(var r=0,e=n.length-1;e>=r;){var u=Math.round(r+(e-r)/2);if(t<n[u])e=u-1;else{if(!(t>n[u]))return u;r=u+1}}return r}function L(n){return function(t){return function(){var r=on.slice.call(arguments),e=P(r);return j(t,e)||(t[e]=n.apply(this,r)),t[e]}}({})}function U(){return sn.key}function B(n,t){return n[t]}function Y(n,t){return j(n,"__mingo__")&&c(t)&&q(Object.assign({},n.__mingo__,t),n.__mingo__)}function J(n,t,r){for(var e=t.split("."),u=n,i=0;i<e.length;i++){var o=null===e[i].match(/^\d+$/);if(o&&s(u)){if(r===!0&&0===i)return u;u=u.map(function(n){return J(n,e[i],!0)}),u.__mingo__={isMulti:!0},1===u.length&&(u=u[0])}else u=B(u,e[i]),r=!1;if(d(u))break}return u}function z(n,t){if(!d(n)){var u,i,o=t.split("."),a=o[0],l=1===o.length||o.slice(1).join("."),c=null!==a.match(/^\d+$/),f=o.length>1;try{s(n)?c?(u=B(n,a),f&&(u=z(u,l)),e(u),u=[u]):(u=[],k(n,function(n){i=z(n,t),d(i)||u.push(i)}),r(u.length>0)):(i=B(n,a),f&&(i=z(i,l)),e(i),u={},u[a]=i)}catch(h){u=void 0}return u}}function G(n,t,r,e){var u=t.split("."),i=u[0],o=1===u.length||u.slice(1).join(".");if(1===u.length)r(n,i);else if(s(n)&&!/^\d+$/.test(i))k(n,function(n){G(n,t,r,e)});else{if(e===!0){var a=j(n,i);a&&!d(n[i])||(n[i]={})}G(n[i],o,r,e)}}function H(n,t,r){G(n,t,function(n,t){n[t]=r},!0)}function V(n,t){G(n,t,function(n,t){s(n)&&/^\d+$/.test(t)?n.splice(parseInt(t),1):c(n)&&delete n[t]})}function W(n){for(var t=0;t<pn.length;t++)if(pn[t](n))return!0;return!1}function K(n){return W(n)||!f(n)}function X(n){if(K(n))return v(n)?{$regex:n}:{$eq:n};if(f(n)){var t=M(n),r=0===E(un(qn),t).length;if(r)return{$eq:n};if(m(t,"$regex")){var e=n.$regex,u=n.$options||"",i="";a(e)&&(i+=e.ignoreCase||u.indexOf("i")>=0?"i":"",i+=e.multiline||u.indexOf("m")>=0?"m":"",i+=e.global||u.indexOf("g")>=0?"g":"",e=new RegExp(e,i)),n.$regex=e,delete n.$options}}return n}function Z(n,t,e,u){if(u=u||{},u.root=u.root||n,m(un(Sn),e))return In[e](n,t,u);if(m(un(Cn),e))return n=Z(n,t,null,u),r(s(n),e+" expression must resolve to an array"),dn[e](n,null,u);if(a(t)&&t.length>0&&"$"===t[0]){if(m(hn,t))return cn[t](n,null,u);if(m(vn,t))return t;var i=hn.filter(function(n){return 0===t.indexOf(n+".")});return 1===i.length&&(i=i[0],"$$ROOT"===i&&(n=u.root),t=t.substr(i.length)),J(n,t.slice(1))}switch(w(t)){case"array":return t.map(function(t){return Z(n,t,null)});case"object":var o={};for(var l in t)if(j(t,l)&&(o[l]=Z(n,t[l],l,u),m(un(Sn),l))){r(1===M(t).length,"Invalid aggregation expression '"+ln(t)+"'"),o=o[l];break}return o;default:return t}}function nn(n,t,e){return d(e)?0>t?(t=Math.max(0,n.length+t),e=n.length-t+1):(e=t,t=0):(0>t&&(t=Math.max(0,n.length+t)),r(e>0,"Invalid argument value for $slice operator. Limit must be a positive number"),e+=t),on.slice.apply(n,[t,e])}function Q(n){var t=n.dataset.reduce(function(n,t){return n+t},0),r=n.dataset.length||1,e=n.sampled===!0?1:0,u=t/(r-e);return Math.sqrt(n.dataset.reduce(function(n,t){return n+Math.pow(t-u,2)},0)/r)}function tn(n,t,r){r=r||{},r.root=r.root||n;var e=Z(n,t,null,r);return m(vn,e)?fn[e](n,t,r):e}function rn(n,t,r){if(m(un(Cn),t))return dn[t](n,r);if(c(r)){var e={};for(var u in r)if(j(r,u)&&(e[u]=rn(n,u,r[u]),m(un(Cn),u))){e=e[u],M(r).length>1&&N("Invalid $group expression '"+ln(r)+"'");break}return e}}function en(n,t){return new Array(Math.max(t-String(n).length+1,0)).join("0")+n}function un(n){return M(Dn[n])}n.VERSION="1.2.0";var on=Array.prototype,an=Object.prototype,ln=JSON.stringify;Function.prototype.bind||(Function.prototype.bind=function(n){if("function"!=typeof this)throw new Error("Function.prototype.bind - what is trying to be bound is not callable");var t=on.slice.call(arguments,1),r=this,e=function(){},u=function(){return r.apply(this instanceof e?this:n,t.concat(on.slice.call(arguments)))};return this.prototype&&(e.prototype=this.prototype),u.prototype=new e,u}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(n){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),r=t.length>>>0;if("function"!=typeof n)throw new TypeError("predicate must be a function");for(var e=arguments[1],u=0;r>u;){var i=t[u];if(n.call(e,i,u,t))return i;u++}}}),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(n){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),r=t.length>>>0;if("function"!=typeof n)throw new TypeError("predicate must be a function");for(var e=arguments[1],u=0;r>u;){var i=t[u];if(n.call(e,i,u,t))return u;u++}return-1}}),Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(n,t){function r(n,t){return n===t||"number"==typeof n&&"number"==typeof t&&isNaN(n)&&isNaN(t)}if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),u=e.length>>>0;if(0===u)return!1;for(var i=0|t,o=Math.max(i>=0?i:u-Math.abs(i),0);u>o;){if(r(e[o],n))return!0;o++}return!1}}),"function"!=typeof Object.assign&&(Object.assign=function(n,t){if(null==n)throw new TypeError("Cannot convert undefined or null to object");for(var r=Object(n),e=on.slice.call(arguments),u=1;u<e.length;u++){var i=e[u];if(null!=i)for(var o in i)an.hasOwnProperty.call(i,o)&&(r[o]=i[o])}return r}),Object.keys||(Object.keys=function(n){if(n!==Object(n))throw new TypeError("Object.keys called on a non-object");var t=[];for(var r in n)an.hasOwnProperty.call(n,r)&&t.push(r);return t}),Object.values||(Object.values=function(n){if(n!==Object(n))throw new TypeError("Object.values called on a non-object");var t=[];for(var r in n)an.hasOwnProperty.call(n,r)&&t.push(n[r]);return t});var sn={key:"_id"};n.setup=function(n){Object.assign(sn,n||{})},n._internal=function(){return Object.assign(t(),{computeValue:Z})};var cn={$$ROOT:function(n,t,r){return r.root},$$CURRENT:function(n){return n}},fn={$$KEEP:function(n){return n},$$PRUNE:function(){},$$DESCEND:function(n,t,r){if(!j(t,"$cond"))return n;var e;return k(n,function(u,i){f(u)&&(s(u)?(e=[],k(u,function(n){c(n)&&(n=tn(n,t,r)),d(n)||e.push(n)})):e=tn(u,t,r),d(e)?delete n[i]:n[i]=e)}),n}},hn=M(cn),vn=M(fn),pn=[a,o,l,h,d,v];n.Aggregator=function(t){return this instanceof n.Aggregator?void(this.__operators=t):new n.Aggregator(t)},n.Aggregator.prototype.run=function(t,r){if(!x(this.__operators))for(var e=0;e<this.__operators.length;e++){var u=this.__operators[e],i=M(u);1===i.length&&m(un(Pn),i[0])?(i=i[0],t=r instanceof n.Query?gn[i].call(r,t,u[i]):gn[i](t,u[i])):N("Invalid aggregation operator '"+i+"'")}return t},n.Cursor=function(t,r,e){return this instanceof n.Cursor?(this.__query=r,this.__collection=t,this.__projection=e||r.__projection,this.__operators={},this.__result=!1,void(this.__position=0)):new n.Cursor(t,r,e)},n.Cursor.prototype={_fetch:function(){var t=this;if(this.__result!==!1)return this.__result;c(this.__projection)&&Object.assign(this.__operators,{$project:this.__projection}),s(this.__collection)||N("Input collection is not of valid type. Must be an Array."),this.__result=this.__collection.filter(this.__query.test,this.__query);var r=[];if(k(["$sort","$skip","$limit","$project"],function(n){if(j(t.__operators,n)){var e={};e[n]=t.__operators[n],r.push(e)}}),r.length>0){var e=new n.Aggregator(r);this.__result=e.run(this.__result,this.__query)}return this.__result},all:function(){return this._fetch()},first:function(){return this.count()>0?this._fetch()[0]:null},last:function(){return this.count()>0?this._fetch()[this.count()-1]:null},count:function(){return this._fetch().length},skip:function(n){return Object.assign(this.__operators,{$skip:n}),this},limit:function(n){return Object.assign(this.__operators,{$limit:n}),this},sort:function(n){return Object.assign(this.__operators,{$sort:n}),this},next:function(){return this.hasNext()?this._fetch()[this.__position++]:null},hasNext:function(){return this.count()>this.__position},max:function(n){return dn.$max(this._fetch(),n)},min:function(n){return dn.$min(this._fetch(),n)},map:function(n){return A(this._fetch(),n)},forEach:function(n){k(this._fetch(),n)}},"function"==typeof Symbol&&Symbol.iterator&&(n.Cursor.prototype[Symbol.iterator]=function(){var n=this;return{next:function(){return n.hasNext()?{done:!1,value:n.next()}:{done:!0}}}}),n.Query=function(t,r){return this instanceof n.Query?(this.__criteria=t,this.__projection=r,this.__compiled=[],void this._compile()):new n.Query(t,r)},n.Query.prototype={_compile:function(){if(!x(this.__criteria)){r(c(this.__criteria),"Criteria must be of type Object");var n;for(var t in this.__criteria){if(j(this.__criteria,t)){var e=this.__criteria[t];if("$where"===t)n={field:t,expr:e};else if(m(["$and","$or","$nor"],t))this._processOperator(t,t,e);else{e=X(e);for(var u in e)j(e,u)&&this._processOperator(t,u,e[u])}}c(n)&&this._processOperator(n.field,n.field,n.expr)}}},_processOperator:function(n,t,r){m(un(qn),t)?this.__compiled.push(yn[t](n,r)):N("Invalid query operator '"+t+"' detected")},test:function(n){for(var t=0;t<this.__compiled.length;t++)if(!this.__compiled[t].test(n))return!1;return!0},find:function(t,r){return new n.Cursor(t,this,r)},remove:function(n){var t=this;return n.reduce(function(n,r){return t.test(r)||n.push(r),n},[])}};var dn={$addToSet:function(n,t){return C(this.$push(n,t))},$sum:function(n,t){return s(n)?l(t)?n.length*t:this.$push(n,t).filter(l).reduce(function(n,t){return n+t},0):0},$max:function(n,t){var r=this.$push(n,t);return r.reduce(function(n,t){return d(n)||t>n?t:n},void 0)},$min:function(n,t){var r=this.$push(n,t);return r.reduce(function(n,t){return d(n)||n>t?t:n},void 0)},$avg:function(n,t){var r=this.$push(n,t).filter(l),e=r.reduce(function(n,t){return n+t},0);return e/(r.length||1)},$push:function(n,t){return d(t)?n:n.map(function(n){return Z(n,t,null)})},$first:function(n,t){return n.length>0?Z(n[0],t):void 0},$last:function(n,t){return n.length>0?Z(n[n.length-1],t):void 0},$stdDevPop:function(n,t){var r=this.$push(n,t).filter(l);return Q({dataset:r,sampled:!1})},$stdDevSamp:function(n,t){var r=this.$push(n,t).filter(l);return Q({dataset:r,sampled:!0})}},gn={$addFields:function(n,t){var e=M(t);return n.map(function(n){return n=u(n),k(e,function(e){var u,i=t[e];if(c(i)){var o=M(i),a=o.filter(function(n){return 0===n.indexOf("$")});x(a)||(r(1===o.length,"Can have only one root operator in $addFields"),a=a[0],i=i[a],u=Z(n,i,a))}else u=Z(n,i,null);G(n,e,function(n,t){n[t]=u},!0)}),n})},$group:function(n,t){var r=t[U()],e=D(n,function(n){return Z(n,r,r)}),u=[];return delete t[U()],k(e.keys,function(n,r){var i={};$(n)||(i[U()]=n);for(var o in t)j(t,o)&&(i[o]=rn(e.groups[r],o,t[o]));u.push(i)}),u},$lookup:function(n,t){function e(n){return P(d(n)?null:n)}var i=t.from,o=t.localField,l=t.foreignField,c=t.as,f="Invalid $lookup expression. ";r(s(i),f+"'from' must be an array"),r(a(l),f+"'foreignField' must be a string"),r(a(o),f+"'localField' must be a string"),r(a(c),f+"'as' must be a string");var h=[],v={};if(i.length<=n.length)k(i,function(n,t){var r=e(n[l]);v[r]=v[r]||[],v[r].push(t)}),k(n,function(n){var t=e(n[o]),r=v[t]||[],a=u(n);a[c]=A(r,function(n){return u(i[n])}),h.push(a)});else{k(n,function(n,t){var r=e(n[o]);v[r]=v[r]||[],v[r].push(t)});var p={};k(i,function(t){var r=e(t[l]),i=v[r]||[];k(i,function(r){var e=p[r]||u(n[r]);e[c]=e[c]||[],e[c].push(u(t)),p[r]=e})});for(var g=0,$=M(p).length;$>g;g++)h.push(p[g])}return h},$match:function(t,r){return new n.Query(r).find(t).all()},$project:function(n,t){if(x(t))return n;var e=[],i=M(t),o=!1,s=[!1,!1];if(k(i,function(n){var e=t[n];n!==U()&&(0===e||e===!1?s[0]=!0:s[1]=!0,r(s[0]!==s[1],"Projection cannot have a mix of inclusion and exclusion."))}),m(i,U())){var f=t[U()];0!==f&&f!==!1||(i=i.filter(y.bind(null,[U()])),r(y(i,U()),"Must not contain collections _id"),o=x(i))}else i.push(U());return k(n,function(n,r){var s={},f=!1,h=!1,v=[];o&&v.push(U()),k(i,function(r){var e,i,o=t[r];if(r!==U()&&0===o&&(h=!0),r===U()&&x(o))e=n[r];else if(a(o))e=Z(n,o,r);else if(1===o||o===!0);else{if(!c(o))return void v.push(r);var p=M(o);p=p.length>1?!1:p[0],m(un(Tn),p)?"$slice"===p?O(o[p]).every(l)?(e=$n[p](n,o[p],r),f=!0):e=Z(n,o,r):e=$n[p](n,o[p],r):e=Z(n,o,r)}i=u(z(n,r)),$(i)||Object.assign(s,i),$(e)||H(s,r,u(e))}),(f||h||o)&&(s=Object.assign(u(n),s),k(v,function(n){V(s,n)})),e.push(s)}),e},$limit:function(n,t){return n.slice(0,t)},$skip:function(n,t){return n.slice(t)},$unwind:function(n,t){for(var r=[],e=t.substr(1),i=0;i<n.length;i++){var o=n[i],a=B(o,e);s(a)?k(a,function(n){var t=u(o);t[e]=n,r.push(t)}):N("Target field '"+e+"' is not of type Array.")}return r},$sort:function(n,t){if(!x(t)&&c(t)){var r=M(t);k(r.reverse(),function(r){var e=D(n,function(n){return J(n,r)}),u={},i=function(n){return u[P(n)]},o=T(e.keys,function(n,t){return u[P(n)]=t,n});-1===t[r]&&o.reverse(),n=[],k(o,function(t){F(n,e.groups[i(t)])})})}return n},$sortByCount:function(n,t){var r={count:{$sum:1}};return r[U()]=t,this.$sort(this.$group(n,r),{count:-1})},$sample:function(n,t){var e=t.size;r(l(e),"$sample size must be a positive integer");for(var u=[],i=0;e>i;i++){var o=Math.floor(Math.random()*n.length);u.push(n[o])}return u},$count:function(n,t){r(a(t)&&""!==t.trim()&&-1===t.indexOf(".")&&"$"!==t.trim()[0],"Invalid expression value for $count");var e={};return e[t]=n.length,e},$replaceRoot:function(n,t){var e=t.newRoot,u=[];return k(n,function(n){n=Z(n,e,null),r(c(n),"$replaceRoot expression must return a valid JS object"),u.push(n)}),u},$redact:function(n,t){return n.map(function(n){return tn(u(n),t)})},$bucket:function(n,t){var e=t.boundaries,u=t["default"],i=e[0],o=e[e.length-1],a=t.output||{count:{$sum:1}};r(e.length>2,"$bucket 'boundaries' expression must have at least 3 elements");for(var l=w(i),s=0,c=e.length-1;c>s;s++)r(l===w(e[s+1]),"$bucket 'boundaries' must all be of the same type"),r(e[s]<e[s+1],"$bucket 'boundaries' must be sorted in ascending order");d(u)||w(t["default"])!==w(i)||r(i>t["default"]||o<t["default"],"$bucket 'default' expression must be out of boundaries range");var f={};return k(e,function(n){f[n]=[]}),d(u)||(f[u]=[]),k(n,function(n){var a=Z(n,t.groupBy,null);if(d(a)||i>a||a>=o)r(!d(u),"$bucket require a default for out of range values"),f[u].push(n);else if(a>=i&&o>a){var l=R(e,a),s=e[Math.max(0,l-1)];f[s].push(n)}else N("$bucket 'groupBy' expression must resolve to a value in range of boundaries")}),e.pop(),d(u)||e.push(u),A(e,function(n){var t=rn(f[n],null,a);return Object.assign(t,{_id:n})})},$bucketAuto:function(n,t){var e=t.output||{count:{$sum:1}},u=t.groupBy,i=(t.granularity,t.buckets);r(i>0,"The $bucketAuto 'buckets' field must be greater than 0, but found: "+i);var o=Math.round(n.length/i);1>o&&(o=1);for(var a=L(Z),l={},s=[],c=T(n,function(n){var t=a(n,u,null);return d(t)?s.push(n):(l[t]||(l[t]=[]),l[t].push(n)),t}),f=[],h=0,v=c.length,p=0;i>p&&v>h;p++){for(var g={},$=[],m=0;o>m&&v>h;m++){var y=a(c[h],u,null);if(d(y)&&(y=null),F($,d(y)?s:l[y]),h+=d(y)?s.length:l[y].length,j(g,"min")||(g.min=y),f.length>0){var b=f[f.length-1];b._id.max=g.min}}p==i-1&&F($,c.slice(h)),f.push(Object.assign(rn($,null,e),{_id:g}))}return f.length>0&&(f[f.length-1]._id.max=a(c[c.length-1],u,null)),f},$facet:function(t,r){return A(r,function(r){return n.aggregate(t,r)})}},$n={$:function(n,t,r){N("$ not implemented")},$elemMatch:function(t,r,e){var u=J(t,e),i=new n.Query(r);if(!d(u)&&s(u))for(var o=0;o<u.length;o++)if(i.test(u[o]))return[u[o]]},$slice:function(n,t,r){var e=J(n,r);return s(e)?s(t)?nn(e,t[0],t[1]):l(t)?nn(e,t):void N("Invalid argument type for $slice projection operator"):e},$stdDevPop:function(n,t,r){var e=Z(n,t,r);return Q({dataset:e,sampled:!1})},$stdDevSamp:function(n,t,r){var e=Z(n,t,r);return Q({dataset:e,sampled:!0})}},mn={$eq:function(n,t){if(q(n,t))return!0;if(s(n)){if(!Y(n,{isMulti:!0}))return-1!==n.findIndex(q.bind(null,t));for(var r=0;r<n.length;r++)if(this.$eq(n[r],t))return!0}return!1},$ne:function(n,t){return!this.$eq(n,t)},$in:function(n,t){return n=O(n),E(n,t).length>0},$nin:function(n,t){return d(n)||!this.$in(n,t)},$lt:function(n,t){return n=O(n).find(function(n){return t>n}),void 0!==n},$lte:function(n,t){return n=O(n).find(function(n){return t>=n}),void 0!==n},$gt:function(n,t){return n=O(n).find(function(n){return n>t}),void 0!==n},$gte:function(n,t){return n=O(n).find(function(n){return n>=t}),void 0!==n},$mod:function(n,t){return n=O(n).find(function(n){return l(n)&&s(t)&&2===t.length&&n%t[0]===t[1]}),void 0!==n},$regex:function(n,t){return n=O(n).find(function(n){return a(n)&&v(t)&&!!n.match(t)}),void 0!==n},$exists:function(n,t){return(t===!1||0===t)&&d(n)||(t===!0||1===t)&&!d(n)},$all:function(n,t){var r=this,e=!1;if(s(n)&&s(t))for(var u=0;u<t.length;u++){if(!c(t[u])||!m(M(t[u]),"$elemMatch"))return E(t,n).length===t.length;e=e||r.$elemMatch(n,t[u].$elemMatch)}return e},$size:function(n,t){return s(n)&&l(t)&&n.length===t},$elemMatch:function(t,r){if(s(t)&&!x(t))for(var e=new n.Query(r),u=0;u<t.length;u++)if(e.test(t[u]))return!0;return!1},$type:function(n,t){switch(t){case 1:case"double":return l(n)&&-1!==(n+"").indexOf(".");case 2:case"string":case 5:case"bindata":return a(n);case 3:case"object":return c(n);case 4:case"array":return s(n);case 6:case"undefined":return d(n);case 8:case"bool":return o(n);case 9:case"date":return h(n);case 10:case"null":return g(n);case 11:case"regex":return v(n);case 16:case"int":return l(n)&&2147483647>=n&&-1===(n+"").indexOf(".");case 18:case"long":return l(n)&&n>2147483647&&0x8000000000000000>=n&&-1===(n+"").indexOf(".");case 19:case"decimal":return l(n);default:return!1}}},yn={$and:function(t,e){r(s(e),"Invalid expression: $and expects value to be an Array");var u=[];return k(e,function(t){u.push(new n.Query(t))}),{test:function(n){for(var t=0;t<u.length;t++)if(!u[t].test(n))return!1;return!0}}},$or:function(t,r){s(r)||N("Invalid expression for $or criteria");var e=[];return k(r,function(t){e.push(new n.Query(t))}),{test:function(n){for(var t=0;t<e.length;t++)if(e[t].test(n))return!0;return!1}}},$nor:function(n,t){s(t)||N("Invalid expression for $nor criteria");var r=this.$or("$or",t);return{test:function(n){return!r.test(n)}}},$not:function(t,r){var e={};e[t]=X(r);var u=new n.Query(e);return{test:function(n){return!u.test(n)}}},$where:function(n,t){return p(t)||(t=new Function("return "+t+";")),{test:function(n){return t.call(n)===!0}}}};k(mn,function(n,t){yn[t]=function(n,t){return function(r,e){return{test:function(u){var i=J(u,r);return n.call(t,i,e)}}}}(n,mn)});var bn={$abs:function(n,t){var r=Z(n,t,null);return null===r||void 0===r?null:Math.abs(r)},$add:function(n,t){var r=Z(n,t,null);return r.reduce(function(n,t){return n+t},0)},$ceil:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e),"$ceil must be a valid expression that resolves to a number."),Math.ceil(e))},$divide:function(n,t){var r=Z(n,t,null);return r[0]/r[1]},$exp:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e),"$exp must be a valid expression that resolves to a number."),Math.exp(e))},$floor:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e),"$floor must be a valid expression that resolves to a number."),Math.floor(e))},$ln:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e),"$ln must be a valid expression that resolves to a number."),Math.log(e))},$log:function(n,t){var e=Z(n,t,null);return r(s(e)&&2===e.length,"$log must be a valid expression that resolves to an array of 2 items"),e.some(isNaN)?NaN:e.some(d)?null:(r(e.every(l),"$log expression must resolve to array of 2 numbers"),Math.log10(e[0])/Math.log10(e[1]))},$log10:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e),"$log10 must be a valid expression that resolves to a number."),Math.log10(e))},$mod:function(n,t){var r=Z(n,t,null);return r[0]%r[1]},$multiply:function(n,t){var r=Z(n,t,null);return r.reduce(function(n,t){return n*t},1)},$pow:function(n,t){var e=Z(n,t,null);return r(s(e)&&2===e.length&&e.every(l),"$pow must be a valid expression that resolves to an array of 2 numbers"),0===e[0]&&e[1]<0&&N("$pow cannot raise 0 to a negative exponent"),Math.pow(e[0],e[1])},$sqrt:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e)&&e>0,"$sqrt must be a valid expression that resolves to a non-negative number."),Math.sqrt(e))},$subtract:function(n,t){var r=Z(n,t,null);return r[0]-r[1]},$trunc:function(n,t){var e=Z(n,t,null);return isNaN(e)?NaN:d(e)?null:(r(l(e)&&e>0,"$trunc must be a valid expression that resolves to a non-negative number."),Math.trunc(e))}},_n={$arrayElemAt:function(n,t){var e=Z(n,t,null);r(s(e)&&2===e.length,"$arrayElemAt expression must resolve to an array of 2 elements"),r(s(e[0]),"First operand to $arrayElemAt must resolve to an array"),r(l(e[1]),"Second operand to $arrayElemAt must resolve to an integer");var u=e[1];return e=e[0],0>u&&Math.abs(u)<=e.length?e[u+e.length]:u>=0&&u<e.length?e[u]:void 0},$concatArrays:function(n,t){var e=Z(n,t,null);return r(s(e)&&2===e.length,"$concatArrays expression must resolve to an array of 2 elements"),e.some(d)?null:e[0].concat(e[1])},$filter:function(n,t){var e=Z(n,t.input,null),u=t.as,i=t.cond;return r(s(e),"'input' expression for $filter must resolve to an array"),e.filter(function(n){var t={};return t["$"+u]=n,Z(t,i,null)===!0})},$indexOfArray:function(n,t){var e=Z(n,t,null);if(d(e))return null;var u=e[0];if(d(u))return null;r(s(u),"First operand for $indexOfArray must resolve to an array.");var i=e[1];if(d(i))return null;var o=e[2]||0,a=e[3]||u.length;return a<u.length&&(u=u.slice(o,a)),u.indexOf(i,o)},$isArray:function(n,t){return s(Z(n,t,null))},$range:function(n,t){for(var r=Z(n,t,null),e=r[0],u=r[1],i=r[2]||1,o=[];u>e&&i>0||e>u&&0>i;)o.push(e),e+=i;return o},$reverseArray:function(n,t){var e=Z(n,t,null);if(d(e))return null;r(s(e),"$reverseArray expression must resolve to an array");for(var u=[],i=e.length-1;i>-1;i--)u.push(e[i]);return u},$reduce:function(n,t){var e=Z(n,t.input,null),u=Z(n,t.initialValue,null),i=t["in"];return d(e)?null:(r(s(e),"'input' expression for $reduce must resolve to an array"),e.reduce(function(n,t){return Z({$value:n,$this:t},i,null)},u))},$size:function(n,t){var r=Z(n,t,null);return s(r)?r.length:void 0},$slice:function(n,t){var r=Z(n,t,null);return nn(r[0],r[1],r[2])},$zip:function(n,t){var e=Z(n,t.inputs,null),u=t.useLongestLength||!1;r(s(e),"'inputs' expression must resolve to an array"),r(o(u),"'useLongestLength' must be a boolean"),s(t.defaults)&&r(b(u),"'useLongestLength' must be set to true to use 'defaults'");var i,a,l=0;for(a=0;a<e.length;a++){if(i=e[a],d(i))return null;r(s(i),"'inputs' expression values must resolve to an array or null"),l=u?Math.max(l,i.length):Math.min(l||i.length,i.length)}var c=[],f=t.defaults||[];for(a=0;l>a;a++)i=e.map(function(n,t){return d(n[a])?f[t]||null:n[a]}),c.push(i);return c}},xn={$and:function(n,t){var r=Z(n,t,null);return b(r)&&r.every(b)},$or:function(n,t){var r=Z(n,t,null);return b(r)&&r.some(b)},$not:function(n,t){return!Z(n,t[0],null)}},On={$cmp:function(n,t){var r=Z(n,t,null);return r[0]>r[1]?1:r[0]<r[1]?-1:0}};k(["$eq","$ne","$gt","$gte","$lt","$lte","$in","$nin"],function(n){On[n]=function(t,r){var e=Z(t,r,null);return mn[n](e[0],e[1])}});var wn={$cond:function(n,t){var r,e,u;s(t)?(3!==t.length&&N("Invalid arguments for $cond operator"),r=t[0],e=t[1],u=t[2]):c(t)&&(r=t["if"],e=t.then,u=t["else"]);var i=Z(n,r,null);return i?Z(n,e,null):Z(n,u,null)},$switch:function(n,t){t.branches||N("Invalid arguments for $switch operator");var r=t.branches.find(function(t){return t["case"]&&t.then||N("Invalid arguments for $switch operator"),Z(n,t["case"],null)});return r?Z(n,r.then,null):t["default"]?Z(n,t["default"],null):void N("Invalid arguments for $switch operator")},$ifNull:function(n,t){r(s(t)&&2===t.length,"Invalid arguments for $ifNull operator");var e=Z(n,t,null);return null===e[0]||void 0===e[0]?e[1]:e[0]}},jn={"%Y":["$year",4],"%m":["$month",2],"%d":["$dayOfMonth",2],"%H":["$hour",2],"%M":["$minute",2],"%S":["$second",2],"%L":["$millisecond",3],"%j":["$dayOfYear",3],"%w":["$dayOfWeek",1],"%U":["$week",2],"%%":"%"},Nn={$dayOfYear:function(n,t){var r=Z(n,t,null);if(h(r)){var e=new Date(r.getFullYear(),0,0),u=r-e,i=864e5;return Math.round(u/i)}},$dayOfMonth:function(n,t){var r=Z(n,t,null);return h(r)?r.getDate():void 0},$dayOfWeek:function(n,t){var r=Z(n,t,null);return h(r)?r.getDay()+1:void 0},$year:function(n,t){var r=Z(n,t,null);return h(r)?r.getFullYear():void 0},$month:function(n,t){var r=Z(n,t,null);return h(r)?r.getMonth()+1:void 0},$week:function(n,t){var r=Z(n,t,null);r=new Date(+r),r.setHours(0,0,0),r.setDate(r.getDate()+4-(r.getDay()||7));var e=new Date(r.getFullYear(),0,1);return Math.floor(((r-e)/864e5+1)/7)},$hour:function(n,t){var r=Z(n,t,null);return h(r)?r.getUTCHours():void 0},$minute:function(n,t){var r=Z(n,t,null);return h(r)?r.getMinutes():void 0},$second:function(n,t){var r=Z(n,t,null);return h(r)?r.getSeconds():void 0},$millisecond:function(n,t){var r=Z(n,t,null);return h(r)?r.getMilliseconds():void 0},$dateToString:function(n,t){for(var r=t.format,e=Z(n,t.date,null),u=r.match(/(%%|%Y|%m|%d|%H|%M|%S|%L|%j|%w|%U)/g),i=0,o=u.length;o>i;i++){var a=jn[u[i]],l=a;if(s(a)){var c=this[a[0]],f=a[1];l=en(c.call(this,n,e),f)}r=r.replace(u[i],l)}return r}},Mn={$literal:function(n,t){return t}},kn={$setEquals:function(n,t){var r=Z(n,t,null),e=C(r[0]),u=C(r[1]);return e.length===u.length&&e.length===E(e,u).length},$setIntersection:function(n,t){var r=Z(n,t,null);return E(r[0],r[1])},$setDifference:function(n,t){var r=Z(n,t,null);return r[0].filter(y.bind(null,r[1]))},$setUnion:function(n,t){var r=Z(n,t,null);return I(r[0],r[1])},$setIsSubset:function(n,t){var r=Z(n,t,null);return E(r[0],r[1]).length===r[0].length},$anyElementTrue:function(n,t){var r=Z(n,t,null)[0];return r.some(b)},$allElementsTrue:function(n,t){var r=Z(n,t,null)[0];return r.every(b)}},An={$concat:function(n,t){var r=Z(n,t,null);return[null,void 0].some(m.bind(null,r))?null:r.join("")},$indexOfBytes:function(n,t){var e=Z(n,t,null);if(d(e[0]))return null;r(a(e[0]),"$indexOfBytes first operand must resolve to a string"),r(a(e[1]),"$indexOfBytes second operand must resolve to a string");var u=e[0],i=e[1],o=e[2],s=e[3];if(r(d(o)||l(o)&&o>=0&&Math.round(o)===o,"$indexOfBytes third operand must resolve to a non-negative integer"),o=o||0,r(d(s)||l(s)&&s>=0&&Math.round(s)===s,"$indexOfBytes fourth operand must resolve to a non-negative integer"),s=s||u.length,o>s)return-1;var c=u.substring(o,s).indexOf(i);return c>-1?c+o:c},$split:function(n,t){var e=Z(n,t,null);return r(a(e[0]),"$split requires an expression that evaluates to a string as a first argument, found: "+w(e[0])),r(a(e[1]),"$split requires an expression that evaluates to a string as a second argument, found: "+w(e[1])),e[0].split(e[1])},$strcasecmp:function(n,t){var r=Z(n,t,null);return r[0]=x(r[0])?"":r[0].toUpperCase(),r[1]=x(r[1])?"":r[1].toUpperCase(),r[0]>r[1]?1:r[0]<r[1]?-1:0},$substr:function(n,t){var r=Z(n,t,null);return a(r[0])?r[1]<0?"":r[2]<0?r[0].substr(r[1]):r[0].substr(r[1],r[2]):""},$toLower:function(n,t){var r=Z(n,t,null);return x(r)?"":r.toLowerCase()},$toUpper:function(n,t){var r=Z(n,t,null);return x(r)?"":r.toUpperCase()}},En={$map:function(n,t){var r=Z(n,t.input,null);s(r)||N("Input expression for $map must resolve to an array");var e=t.as,u=t["in"],i="$"+e,o=n[i];return r.map(function(t){n[i]=t;var r=Z(n,u,null);return $(o)?delete n[i]:n[i]=o,r})},$let:function(n,t){var r=t.vars,e=t["in"],u={},i=M(r);k(i,function(t){var e=Z(n,r[t],null),i="$"+t;u[i]=n[i],n[i]=e});var o=Z(n,e,null);return k(i,function(t){var r="$"+t;$(u[r])?delete n[r]:n[r]=u[r]}),o}},In=Object.assign({},bn,_n,xn,On,wn,Nn,Mn,kn,An,En),qn=n.OP_QUERY="query",Cn=n.OP_GROUP="group",Sn=n.OP_AGGREGATE="aggregate",Pn=n.OP_PIPELINE="pipeline",Tn=n.OP_PROJECTION="projection",Dn={aggregate:In,group:dn,pipeline:gn,projection:$n,query:yn};n.addOperators=function(n,t){var e=t({computeValue:Z,key:U,ops:un,resolve:J});r(j(Dn,n),"Could not identify operator class '"+n+"'");var u=Dn[n];k(e,function(t,e){r(/^\$\w+$/.test(e),"Invalid operator name '"+e+"'"),r(!j(u,e),"Operator "+e+" is already defined for "+n+" operators")});var i={};switch(n){case qn:k(e,function(n,t){i[t]=function(n,r){return function(e,u){return{test:function(i){var a=J(i,e),l=n.call(r,e,a,u);return o(l)?l:l instanceof Query?l.test(i):void N("Invalid return type for '"+t+"'. Must return a Boolean or Mingo.Query")}}}}(n,e)});break;case Tn:k(e,function(n,t){
i[t]=function(n,t){return function(r,e,u){var i=J(r,u);return n.call(t,u,i,e)}}(n,e)});break;default:k(e,function(n,t){i[t]=function(n,t){return function(){var r=on.slice.call(arguments);return n.apply(t,r)}}(n,e)})}Object.assign(Dn[n],i)},n.find=function(t,r,e){return new n.Query(r).find(t,e)},n.remove=function(t,r){return new n.Query(r).remove(t)},n.aggregate=function(t,r){return s(r)||N("Aggregation pipeline must be an array"),new n.Aggregator(r).run(t)},n.CollectionMixin={query:function(t,r){return n.find(this.toJSON(),t,r)},aggregate:function(t){return n.aggregate.call(null,this.toJSON(),t)}}});
//# sourceMappingURL=dist/mingo.min.map
// mingo.js 1.3.0
// Copyright (c) 2017 Francis Asante
// https://github.com/kofrasa/mingo
// MIT
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.mingo=t()}(this,function(){"use strict";function n(n,t){y(n)&&O(t)}function t(n){switch(r(n)){case"array":return n.map(t);case"object":return q(n,t);default:return n}}function e(n){return null===n?"Null":void 0===n?"Undefined":n.constructor.name}function r(n){return e(n).toLowerCase()}function u(n){return"boolean"===r(n)}function i(n){return"string"===r(n)}function o(n){return"number"===r(n)}function a(n){return"array"===r(n)}function l(n){return"object"===r(n)}function s(n){return n===Object(n)}function c(n){return"date"===r(n)}function f(n){return"regexp"===r(n)}function v(n){return"function"===r(n)}function h(n){return d(n)||p(n)}function d(n){return"null"===r(n)}function p(n){return"undefined"===r(n)}function g(n,t){return n.includes(t)}function $(n,t){return!n.includes(t)}function m(n){return!!n}function y(n){return!n}function b(n){return h(n)||a(n)&&0===n.length||l(n)&&0===k(n).length||!n}function _(n){return a(n)?n:[n]}function x(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function O(n){throw new Error(n)}function k(n){return Object.keys(n)}function j(n,t){n.__mingo__=Object.assign(n.__mingo__||{},t)}function N(n,t){return x(n,"__mingo__")&&l(t)&&I(Object.assign({},n.__mingo__,t),n.__mingo__)}function w(n){x(n,"__mingo__")&&delete n.__mingo__}function M(t,e){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;n(t===Object(t),"Cannot iterate over object of type '"+r(t)+"'");var i=!1,o=function(){i=!0,O("halt")};if(a(t))for(var l=0,s=t.length;l<s;l++)try{e.call(u,t[l],l,t,o)}catch(t){return void n(i,t.message)}else for(var c in t)if(x(t,c))try{e.call(u,t[c],c,t,o)}catch(t){return void n(i,t.message)}}function q(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(a(n))return n.map(t,e);if(l(n)){for(var r,u={},i=k(n),o=0,s=i.length;o<s;o++)r=i[o],u[r]=t.call(e,n[r],r);return u}O("Input must be an Array or Object type")}function S(n,t){return n.filter(g.bind(null,t))}function A(n,t){var e=[];return U(e,n),U(e,t.filter($.bind(null,n))),e}function I(n,t){if(n===t)return!0;var e=r(n);if(e!==r(t)||"function"===e)return!1;if("number"===e&&isNaN(n)&&isNaN(t))return!0;if(g(["date","regexp"],e))return n.toString()===t.toString();if("array"===e){if(n.length===t.length&&0===n.length)return!0;if(n.length!==t.length)return!1;for(var u=0,i=n.length;u<i;u++)if(!I(n[u],t[u]))return!1}else{if(![n,t].every(l))return P(n)===P(t);var o=k(n),a=k(t);if(o.length!==a.length)return!1;if(o.sort(),a.sort(),!I(o,a))return!1;for(var s=0,c=o.length;s<c;s++){var f=o[s];if(!I(n[f],t[f]))return!1}}return!0}function E(n){var t={},e=[];return M(n,function(n){var r=P(n);x(t,r)||(e.push(n),t[r]=0)}),e}function C(n){return(Math.E+Math.random()).toString(36).slice(2,n+2)}function D(n){var t=r(n);switch(t){case"function":return C(7);case"boolean":case"number":case"regex":return n.toString();case"string":return JSON.stringify(n);case"date":return n.toISOString();case"null":case"undefined":return t;case"array":return"["+q(n,function(n){return""+D(n)})+"]";default:var u=l(n)?"":e(n)+"|",i=k(n);return i.sort(),u+"{"+q(i,function(t){return D(t)+":"+D(n[t])})+"}"}}function P(n){var t=0,e=void 0,r=void 0,u=void 0,i=D(n);if(0===i.length)return t;for(e=0,u=i.length;e<u;e++)r=i.charCodeAt(e),t=(t<<5)-t+r,t|=0;return t.toString()}function R(t,e){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,u={},i=[],o=t.length,a=[],l=0;l<o;l++){var s=t[l],c=e.call(r,s,l);if(h(c))a.push(s);else{var f=P(s);x(u,f)||(u[f]=[c,l]),i.push(s)}}return i.sort(function(n,t){var e=u[P(n)],r=u[P(t)];return e[0]<r[0]?-1:e[0]>r[0]?1:e[1]<r[1]?-1:e[1]>r[1]?1:0}),U(a,i),n(a.length===t.length,"sortBy must retain collection length"),a}function T(t,e,r){var u={keys:[],groups:[]},i={};return M(t,function(n){var t=e.call(r,n),o=P(t),a=-1;p(i[o])&&(a=u.keys.length,i[o]=a,u.keys.push(t),u.groups.push([])),a=i[o],u.groups[a].push(n)}),n(u.keys.length===u.groups.length,"Cardinality must be equal for groups and keys"),u}function U(n,t){Array.prototype.push.apply(n,t)}function F(n,t){for(var e=0,r=n.length-1;e<=r;){var u=Math.round(e+(r-e)/2);if(t<n[u])r=u-1;else{if(!(t>n[u]))return u;e=u+1}}return e}function L(n){var t=this;return function(e){return function(){for(var r=arguments.length,u=Array(r),i=0;i<r;i++)u[i]=arguments[i];var o=P(u);return x(e,o)||(e[o]=n.apply(t,u)),e[o]}}({})}function B(t,e,r){if(g(H(Dn),e))return cn[e](t,r);if(l(r)){var u={};return M(r,function(e,i,o,a){u[i]=B(t,i,r[i]),g(H(Dn),i)&&(u=u[i],n(1===k(r).length,"Invalid $group expression '"+JSON.stringify(r)+"'"),a())}),u}}function Y(t,e){return n(a(e),"Aggregation pipeline must be an array"),new gn(e).run(t)}function J(n,t,e){return new bn(t).find(n,e)}function z(n,t){return new bn(t).remove(n)}function G(n,t){return new Array(Math.max(t-String(n).length+1,0)).join("0")+n}function H(n){return k(En[n])}function Q(t,e){var r=e(ln());n(x(En,t),"Could not identify operator class '"+t+"'");var i=En[t];M(r,function(e,r){n(/^\$\w+$/.test(r),"Invalid operator name '"+r+"'"),n(!x(i,r),"Operator "+r+" is already defined for "+t+" operators")});var o={};switch(t){case Tn:M(r,function(n,t){o[t]=function(n,e){return function(r,i){return{test:function(o){var a=W(o,r),l=n.call(e,r,a,i);return u(l)?l:l instanceof bn?l.test(o):void O("Invalid return type for '"+t+"'. Must return a Boolean or Query")}}}}(n,r)});break;case Rn:M(r,function(n,t){o[t]=function(n,t){return function(e,r,u){var i=W(e,u);return n.call(t,u,i,r)}}(n,r)});break;default:M(r,function(n,t){o[t]=function(n,t){return function(){for(var e=arguments.length,r=Array(e),u=0;u<e;u++)r[u]=arguments[u];return n.apply(t,r)}}(n,r)})}Object.assign(En[t],o)}function V(){return Un.key}function K(n,t){return n[t]}function W(n,t){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=t.split("."),u=n;n:for(var i=0;i<r.length;i++){var o=function(n){if(null===r[n].match(/^\d+$/)&&a(u)){if(!0===e&&0===n)return{v:u};u=u.map(function(t){return W(t,r[n],!0)}),j(u,{isMulti:!0}),1===u.length&&(u=u[0])}else u=K(u,r[n]),e=!1;if(h(u))return"break"}(i);switch(o){case"break":break n;default:if("object"===(void 0===o?"undefined":hn(o)))return o.v}}return u}function X(t,e){if(!h(t)){var r=e.split("."),u=r[0],i=1===r.length||r.slice(1).join("."),o=null!==u.match(/^\d+$/),l=r.length>1,s=void 0,c=void 0;try{a(t)?o?(s=K(t,u),l&&(s=X(s,i)),n(!p(s)),s=[s]):(s=[],M(t,function(n){c=X(n,e),h(c)||s.push(c)}),n(s.length>0)):(c=K(t,u),l&&(c=X(c,i)),n(!p(c)),s={},s[u]=c)}catch(n){s=void 0}return s}}function Z(n,t,e){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],u=t.split("."),i=u[0],o=1===u.length||u.slice(1).join(".");if(1===u.length)e(n,i);else if(a(n)&&!/^\d+$/.test(i))M(n,function(n){Z(n,t,e,r)});else{if(!0===r){var l=x(n,i);l&&!h(n[i])||(n[i]={})}Z(n[i],o,e,r)}}function nn(n,t,e){Z(n,t,function(n,t){n[t]=e},!0)}function tn(n,t){Z(n,t,function(n,t){a(n)&&/^\d+$/.test(t)?n.splice(parseInt(t),1):l(n)&&delete n[t]})}function en(n){if(g(sn,r(n)))return f(n)?{$regex:n}:{$eq:n};if(s(n)){var t=k(n);if(0===S(H(Tn),t).length)return{$eq:n};if(g(t,"$regex")){var e=n.$regex,u=n.$options||"",o="";i(e)&&(o+=e.ignoreCase||u.indexOf("i")>=0?"i":"",o+=e.multiline||u.indexOf("m")>=0?"m":"",o+=e.global||u.indexOf("g")>=0?"g":"",e=new RegExp(e,o)),n.$regex=e,delete n.$options}}return n}function rn(t,e,u){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(o=o||{},o.root=o.root||t,g(H(Cn),u))return In[u](t,e,o);if(g(H(Dn),u))return t=rn(t,e,null,o),n(a(t),u+" expression must resolve to an array"),cn[u](t,null,o);if(i(e)&&e.length>0&&"$"===e[0]){if(g(Bn,e))return Fn[e](t,null,o);if(g(Yn,e))return e;var l=Bn.filter(function(n){return 0===e.indexOf(n+".")});return 1===l.length&&(l=l[0],"$$ROOT"===l&&(t=o.root),e=e.substr(l.length)),W(t,e.slice(1))}switch(r(e)){case"array":return e.map(function(n){return rn(t,n,null)});case"object":var s={};return M(e,function(r,u,i,a){s[u]=rn(t,r,u,o),g(H(Cn),u)&&(n(1===k(e).length,"Invalid aggregation expression '"+JSON.stringify(e)+"'"),s=s[u],a())}),s;default:return e}}function un(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return h(r)?e<0?(e=Math.max(0,t.length+e),r=t.length-e+1):(r=e,e=0):(e<0&&(e=Math.max(0,t.length+e)),n(r>0,"Invalid argument value for $slice operator. Limit must be a positive number"),r+=e),Array.prototype.slice.apply(t,[e,r])}function on(n){var t=n.data.reduce(function(n,t){return n+t},0),e=n.data.length||1,r=!0===n.sampled?1:0,u=t/(e-r);return Math.sqrt(n.data.reduce(function(n,t){return n+Math.pow(t-u,2)},0)/e)}function an(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e=e||{},e.root=e.root||n;var r=rn(n,t,null,e);return g(Yn,r)?Ln[r](n,t,e):r}function ln(){return{computeValue:rn,idKey:V,ops:H,resolve:W,assert:n,clone:t,each:M,err:O,getType:e,has:x,isArray:a,isBoolean:u,isDate:c,isEmpty:b,isEqual:I,isFunction:v,isNil:h,isNull:d,isNumber:o,isObject:l,isRegExp:f,isString:i,isUndefined:p,keys:k}}var sn=["null","undefined","boolean","number","string","date","regexp"],cn={$addToSet:function(n,t){return E(this.$push(n,t))},$sum:function(n,t){return a(n)?o(t)?n.length*t:this.$push(n,t).filter(o).reduce(function(n,t){return n+t},0):0},$max:function(n,t){return this.$push(n,t).reduce(function(n,t){return h(n)||t>n?t:n},void 0)},$min:function(n,t){return this.$push(n,t).reduce(function(n,t){return h(n)||t<n?t:n},void 0)},$avg:function(n,t){var e=this.$push(n,t).filter(o);return e.reduce(function(n,t){return n+t},0)/(e.length||1)},$push:function(n,t){return h(t)?n:n.map(function(n){return rn(n,t,null)})},$first:function(n,t){return n.length>0?rn(n[0],t):void 0},$last:function(n,t){return n.length>0?rn(n[n.length-1],t):void 0},$stdDevPop:function(n,t){return on({data:this.$push(n,t).filter(o),sampled:!1})},$stdDevSamp:function(n,t){return on({data:this.$push(n,t).filter(o),sampled:!0})}},fn={$:function(n,t,e){O("$ not implemented")},$elemMatch:function(n,t,e){var r=W(n,e),u=new bn(t);if(!h(r)&&a(r))for(var i=0;i<r.length;i++)if(u.test(r[i]))return[r[i]]},$slice:function(n,t,e){var r=W(n,e);return a(r)?a(t)?un(r,t[0],t[1]):o(t)?un(r,t):void O("Invalid argument type for $slice projection operator"):r},$stdDevPop:function(n,t,e){return on({data:rn(n,t,e),sampled:!1})},$stdDevSamp:function(n,t,e){return on({data:rn(n,t,e),sampled:!0})}},vn={$addFields:function(e,r){var u=k(r);return e.map(function(e){return e=t(e),M(u,function(t){var u=r[t],i=void 0;if(l(u)){var o=k(u),a=o.filter(function(n){return 0===n.indexOf("$")});b(a)||(n(1===o.length,"Can have only one root operator in $addFields"),a=a[0],u=u[a],i=rn(e,u,a))}else i=rn(e,u,null);Z(e,t,function(n,t){n[t]=i},!0)}),e})},$group:function(n,t){var e=t[V()],r=T(n,function(n){return rn(n,e,e)}),u=[];return delete t[V()],M(r.keys,function(n,e){var i={};p(n)||(i[V()]=n),M(t,function(n,t){i[t]=B(r.groups[e],t,n)}),u.push(i)}),u},$lookup:function(e,r){function u(n){return P(h(n)?null:n)}var o=r.from,l=r.localField,s=r.foreignField,c=r.as,f="Invalid $lookup expression. ";n(a(o),f+"'from' must be an array"),n(i(s),f+"'foreignField' must be a string"),n(i(l),f+"'localField' must be a string"),n(i(c),f+"'as' must be a string");var v=[],d={};if(o.length<=e.length)M(o,function(n,t){var e=u(n[s]);d[e]=d[e]||[],d[e].push(t)}),M(e,function(n){var e=u(n[l]),r=d[e]||[],i=t(n);i[c]=r.map(function(n){return t(o[n])}),v.push(i)});else{M(e,function(n,t){var e=u(n[l]);d[e]=d[e]||[],d[e].push(t)});var p={};M(o,function(n){var r=u(n[s]);M(d[r]||[],function(r){var u=p[r]||t(e[r]);u[c]=u[c]||[],u[c].push(t(n)),p[r]=u})});for(var g=0,$=k(p).length;g<$;g++)v.push(p[g])}return v},$match:function(n,t){return new bn(t).find(n).all()},$project:function(e,r){if(b(r))return e;var u=[],a=k(r),s=!1,c=V(),f=[!1,!1];if(M(r,function(t,e){e!==c&&(0===t||!1===t?f[0]=!0:f[1]=!0,n(f[0]!==f[1],"Projection cannot have a mix of inclusion and exclusion."))}),g(a,c)){var v=r[c];0!==v&&!1!==v||(a=a.filter($.bind(null,[c])),n($(a,c),"Must not contain collections id key"),s=b(a))}else a.push(c);return M(e,function(n){var e={},f=!1,v=!1,h=[];s&&h.push(c),M(a,function(u){var a=r[u],s=void 0;if(u!==c&&0===a&&(v=!0),u===c&&b(a))s=n[u];else if(i(a))s=rn(n,a,u);else if(1===a||!0===a);else{if(!l(a))return void h.push(u);var d=k(a);d=!(d.length>1)&&d[0],g(H(Rn),d)?"$slice"===d?_(a[d]).every(o)?(s=fn[d](n,a[d],u),f=!0):s=rn(n,a,u):s=fn[d](n,a[d],u):s=rn(n,a,u)}var $=t(X(n,u));p($)||Object.assign(e,$),p(s)||nn(e,u,t(s))}),(f||v||s)&&(e=Object.assign(t(n),e),M(h,function(n){return tn(e,n)})),u.push(e)}),u},$limit:function(n,t){return n.slice(0,t)},$skip:function(n,t){return n.slice(t)},$unwind:function(e,r){var u=[],i=r.substr(1);return M(e,function(e){var r=K(e,i);n(a(r),"Target field '"+i+"' is not of type Array."),M(r,function(n){var r=t(e);r[i]=n,u.push(r)})}),u},$sort:function(n,t){if(!b(t)&&l(t)){M(k(t).reverse(),function(e){var r=T(n,function(n){return W(n,e)}),u={},i=function(n){return u[P(n)]},o=R(r.keys,function(n,t){return u[P(n)]=t,n});-1===t[e]&&o.reverse(),n=[],M(o,function(t){return U(n,r.groups[i(t)])})})}return n},$sortByCount:function(n,t){var e={count:{$sum:1}};return e[V()]=t,this.$sort(this.$group(n,e),{count:-1})},$sample:function(t,e){var r=e.size;n(o(r),"$sample size must be a positive integer");for(var u=[],i=t.length,a=0;a<r;a++){var l=Math.floor(Math.random()*i);u.push(t[l])}return u},$count:function(t,e){n(i(e)&&""!==e.trim()&&-1===e.indexOf(".")&&"$"!==e.trim()[0],"Invalid expression value for $count");var r={};return r[e]=t.length,r},$replaceRoot:function(t,e){var r=e.newRoot,u=[];return M(t,function(t){t=rn(t,r,null),n(l(t),"$replaceRoot expression must return a valid JS object"),u.push(t)}),u},$redact:function(n,e){return n.map(function(n){return an(t(n),e)})},$bucket:function(t,r){var u=r.boundaries,i=r.default,o=u[0],a=u[u.length-1],l=r.output||{count:{$sum:1}};n(u.length>2,"$bucket 'boundaries' expression must have at least 3 elements");for(var s=e(o),c=0,f=u.length-1;c<f;c++)n(s===e(u[c+1]),"$bucket 'boundaries' must all be of the same type"),n(u[c]<u[c+1],"$bucket 'boundaries' must be sorted in ascending order");h(i)||e(r.default)!==e(o)||n(o>r.default||a<r.default,"$bucket 'default' expression must be out of boundaries range");var v={};return M(u,function(n){return v[n]=[]}),h(i)||(v[i]=[]),M(t,function(t){var e=rn(t,r.groupBy,null);if(h(e)||e<o||e>=a)n(!h(i),"$bucket require a default for out of range values"),v[i].push(t);else if(e>=o&&e<a){var l=F(u,e),s=u[Math.max(0,l-1)];v[s].push(t)}else O("$bucket 'groupBy' expression must resolve to a value in range of boundaries")}),u.pop(),h(i)||u.push(i),q(u,function(n){var t=B(v[n],null,l);return Object.assign(t,{_id:n})})},$bucketAuto:function(t,e){var r=e.output||{count:{$sum:1}},u=e.groupBy,i=(e.granularity,e.buckets);n(i>0,"The $bucketAuto 'buckets' field must be greater than 0, but found: "+i);var o=Math.round(t.length/i);o<1&&(o=1);for(var a=L(rn),l={},s=[],c=R(t,function(n){var t=a(n,u,null);return h(t)?s.push(n):(l[t]||(l[t]=[]),l[t].push(n)),t}),f=[],v=0,d=0,p=c.length;d<i&&v<p;d++){for(var g={},$=[],m=0;m<o&&v<p;m++){var y=a(c[v],u,null);if(h(y)&&(y=null),U($,h(y)?s:l[y]),v+=h(y)?s.length:l[y].length,x(g,"min")||(g.min=y),f.length>0){f[f.length-1]._id.max=g.min}}d==i-1&&U($,c.slice(v)),f.push(Object.assign(B($,null,r),{_id:g}))}return f.length>0&&(f[f.length-1]._id.max=a(c[c.length-1],u,null)),f},$facet:function(n,t){return q(t,function(t){return Y(n,t)})}},hn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},dn=function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")},pn=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),gn=function(){function n(t){dn(this,n),this.__operators=t}return pn(n,[{key:"run",value:function(n,t){return b(this.__operators)||M(this.__operators,function(e){var r=k(e);1===r.length&&g(H(Pn),r[0])?(r=r[0],n=t instanceof bn?vn[r].call(t,n,e[r]):vn[r](n,e[r])):O("Invalid aggregation operator '"+r+"'")}),n}}]),n}(),$n=function(){function t(n,e,r){dn(this,t),this.__query=e,this.__collection=n,this.__projection=r||e.__projection,this.__operators={},this.__result=!1,this.__position=0}return pn(t,[{key:"_fetch",value:function(){var t=this;if(!1!==this.__result)return this.__result;l(this.__projection)&&Object.assign(this.__operators,{$project:this.__projection}),n(a(this.__collection),"Input collection is not of valid type. Must be an Array."),this.__result=this.__collection.filter(this.__query.test,this.__query);var e=[];if(M(["$sort","$skip","$limit","$project"],function(n){if(x(t.__operators,n)){var r={};r[n]=t.__operators[n],e.push(r)}}),e.length>0){var r=new gn(e);this.__result=r.run(this.__result,this.__query)}return this.__result}},{key:"all",value:function(){return this._fetch()}},{key:"first",value:function(){return this.count()>0?this._fetch()[0]:null}},{key:"last",value:function(){return this.count()>0?this._fetch()[this.count()-1]:null}},{key:"count",value:function(){return this._fetch().length}},{key:"skip",value:function(n){return Object.assign(this.__operators,{$skip:n}),this}},{key:"limit",value:function(n){return Object.assign(this.__operators,{$limit:n}),this}},{key:"sort",value:function(n){return Object.assign(this.__operators,{$sort:n}),this}},{key:"next",value:function(){return this.hasNext()?this._fetch()[this.__position++]:null}},{key:"hasNext",value:function(){return this.count()>this.__position}},{key:"max",value:function(n){return cn.$max(this._fetch(),n)}},{key:"min",value:function(n){return cn.$min(this._fetch(),n)}},{key:"map",value:function(n){return this._fetch().map(n)}},{key:"forEach",value:function(n){M(this._fetch(),n)}},{key:Symbol.iterator,value:function(){var n=this;return{next:function(){return n.hasNext()?{done:!1,value:n.next()}:{done:!0}}}}}]),t}(),mn={$eq:function(n,t){if(I(n,t))return!0;if(h(n)&&h(t))return!0;if(a(n)){if(!N(n,{isMulti:!0}))return-1!==n.findIndex(I.bind(null,t));try{for(var e=0;e<n.length;e++)if(this.$eq(n[e],t))return!0}finally{w(n)}}return!1},$ne:function(n,t){return!this.$eq(n,t)},$in:function(n,t){return n=_(n),S(n,t).length>0},$nin:function(n,t){return h(n)||!this.$in(n,t)},$lt:function(n,t){return void 0!==(n=_(n).find(function(n){return n<t}))},$lte:function(n,t){return void 0!==(n=_(n).find(function(n){return n<=t}))},$gt:function(n,t){return void 0!==(n=_(n).find(function(n){return n>t}))},$gte:function(n,t){return void 0!==(n=_(n).find(function(n){return n>=t}))},$mod:function(n,t){return void 0!==(n=_(n).find(function(n){return o(n)&&a(t)&&2===t.length&&n%t[0]===t[1]}))},$regex:function(n,t){return void 0!==(n=_(n).find(function(n){return i(n)&&f(t)&&!!n.match(t)}))},$exists:function(n,t){return(!1===t||0===t)&&h(n)||(!0===t||1===t)&&!h(n)},$all:function(n,t){var e=!1;if(a(n)&&a(t))for(var r=0,u=t.length;r<u;r++){if(!l(t[r])||!g(k(t[r]),"$elemMatch"))return S(t,n).length===u;e=e||this.$elemMatch(n,t[r].$elemMatch)}return e},$size:function(n,t){return a(n)&&o(t)&&n.length===t},$elemMatch:function(n,t){if(a(n)&&!b(n))for(var e=new bn(t),r=0,u=n.length;r<u;r++)if(e.test(n[r]))return!0;return!1},$type:function(n,t){switch(t){case 1:case"double":return o(n)&&-1!==(n+"").indexOf(".");case 2:case"string":case 5:case"bindata":return i(n);case 3:case"object":return l(n);case 4:case"array":return a(n);case 6:case"undefined":return h(n);case 8:case"bool":return u(n);case 9:case"date":return c(n);case 10:case"null":return d(n);case 11:case"regex":return f(n);case 16:case"int":return o(n)&&n<=2147483647&&-1===(n+"").indexOf(".");case 18:case"long":return o(n)&&n>2147483647&&n<=0x8000000000000000&&-1===(n+"").indexOf(".");case 19:case"decimal":return o(n);default:return!1}}},yn={$and:function(t,e){n(a(e),"Invalid expression: $and expects value to be an Array");var r=[];return M(e,function(n){return r.push(new bn(n))}),{test:function(n){for(var t=0;t<r.length;t++)if(!r[t].test(n))return!1;return!0}}},$or:function(t,e){n(a(e),"Invalid expression. $or expects value to be an Array");var r=[];return M(e,function(n){return r.push(new bn(n))}),{test:function(n){for(var t=0;t<r.length;t++)if(r[t].test(n))return!0;return!1}}},$nor:function(t,e){n(a(e),"Invalid expression. $nor expects value to be an Array");var r=this.$or("$or",e);return{test:function(n){return!r.test(n)}}},$not:function(n,t){var e={};e[n]=en(t);var r=new bn(e);return{test:function(n){return!r.test(n)}}},$where:function(n,t){return v(t)||(t=new Function("return "+t+";")),{test:function(n){return!0===t.call(n)}}}};M(mn,function(n,t){yn[t]=function(n,t){return function(e,r){return{test:function(u){var i=W(u,e);return n.call(t,i,r)}}}}(n,mn)});var bn=function(){function t(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};dn(this,t),this.__criteria=n,this.__projection=e,this.__compiled=[],this._compile()}return pn(t,[{key:"_compile",value:function(){var t=this;if(!b(this.__criteria)){n(l(this.__criteria),"Criteria must be of type Object");var e=void 0;M(this.__criteria,function(n,r){"$where"===r?e={field:r,expr:n}:g(["$and","$or","$nor"],r)?t._processOperator(r,r,n):(n=en(n),M(n,function(n,e){t._processOperator(r,e,n)})),l(e)&&t._processOperator(e.field,e.field,e.expr)})}}},{key:"_processOperator",value:function(n,t,e){g(H(Tn),t)?this.__compiled.push(yn[t](n,e)):O("Invalid query operator '"+t+"' detected")}},{key:"test",value:function(n){for(var t=0,e=this.__compiled.length;t<e;t++)if(!this.__compiled[t].test(n))return!1;return!0}},{key:"find",value:function(n,t){return new $n(n,this,t)}},{key:"remove",value:function(n){var t=this;return n.reduce(function(n,e){return t.test(e)||n.push(e),n},[])}}]),t}(),_n={$abs:function(n,t){var e=rn(n,t,null);return null===e||void 0===e?null:Math.abs(e)},$add:function(n,t){return rn(n,t,null).reduce(function(n,t){return n+t},0)},$ceil:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r),"$ceil must be a valid expression that resolves to a number."),Math.ceil(r))},$divide:function(n,t){var e=rn(n,t,null);return e[0]/e[1]},$exp:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r),"$exp must be a valid expression that resolves to a number."),Math.exp(r))},$floor:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r),"$floor must be a valid expression that resolves to a number."),Math.floor(r))},$ln:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r),"$ln must be a valid expression that resolves to a number."),Math.log(r))},$log:function(t,e){var r=rn(t,e,null);return n(a(r)&&2===r.length,"$log must be a valid expression that resolves to an array of 2 items"),r.some(isNaN)?NaN:r.some(h)?null:(n(r.every(o),"$log expression must resolve to array of 2 numbers"),Math.log10(r[0])/Math.log10(r[1]))},$log10:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r),"$log10 must be a valid expression that resolves to a number."),Math.log10(r))},$mod:function(n,t){var e=rn(n,t,null);return e[0]%e[1]},$multiply:function(n,t){return rn(n,t,null).reduce(function(n,t){return n*t},1)},$pow:function(t,e){var r=rn(t,e,null);return n(a(r)&&2===r.length&&r.every(o),"$pow must be a valid expression that resolves to an array of 2 numbers"),n(!(0===r[0]&&r[1]<0),"$pow cannot raise 0 to a negative exponent"),Math.pow(r[0],r[1])},$sqrt:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r)&&r>0,"$sqrt must be a valid expression that resolves to a non-negative number."),Math.sqrt(r))},$subtract:function(n,t){var e=rn(n,t,null);return e[0]-e[1]},$trunc:function(t,e){var r=rn(t,e,null);return isNaN(r)?NaN:h(r)?null:(n(o(r)&&r>0,"$trunc must be a valid expression that resolves to a non-negative number."),Math.trunc(r))}},xn={$arrayElemAt:function(t,e){var r=rn(t,e,null);n(a(r)&&2===r.length,"$arrayElemAt expression must resolve to an array of 2 elements"),n(a(r[0]),"First operand to $arrayElemAt must resolve to an array"),n(o(r[1]),"Second operand to $arrayElemAt must resolve to an integer");var u=r[1];return r=r[0],u<0&&Math.abs(u)<=r.length?r[u+r.length]:u>=0&&u<r.length?r[u]:void 0},$concatArrays:function(t,e){var r=rn(t,e,null);return n(a(r)&&2===r.length,"$concatArrays expression must resolve to an array of 2 elements"),r.some(h)?null:r[0].concat(r[1])},$filter:function(t,e){var r=rn(t,e.input,null),u=e.as,i=e.cond;return n(a(r),"'input' expression for $filter must resolve to an array"),r.filter(function(n){var t={};return t["$"+u]=n,!0===rn(t,i,null)})},$indexOfArray:function(t,e){var r=rn(t,e,null);if(h(r))return null;var u=r[0];if(h(u))return null;n(a(u),"First operand for $indexOfArray must resolve to an array.");var i=r[1];if(h(i))return null;var o=r[2]||0,l=r[3]||u.length;return l<u.length&&(u=u.slice(o,l)),u.indexOf(i,o)},$isArray:function(n,t){return a(rn(n,t,null))},$range:function(n,t){for(var e=rn(n,t,null),r=e[0],u=e[1],i=e[2]||1,o=[];r<u&&i>0||r>u&&i<0;)o.push(r),r+=i;return o},$reverseArray:function(t,e){var r=rn(t,e,null);if(h(r))return null;n(a(r),"$reverseArray expression must resolve to an array");for(var u=[],i=r.length-1;i>-1;i--)u.push(r[i]);return u},$reduce:function(t,e){var r=rn(t,e.input,null),u=rn(t,e.initialValue,null),i=e.in;return h(r)?null:(n(a(r),"'input' expression for $reduce must resolve to an array"),r.reduce(function(n,t){return rn({$value:n,$this:t},i,null)},u))},$size:function(n,t){var e=rn(n,t,null);return a(e)?e.length:void 0},$slice:function(n,t){var e=rn(n,t,null);return un(e[0],e[1],e[2])},$zip:function(t,e){var r=rn(t,e.inputs,null),i=e.useLongestLength||!1;n(a(r),"'inputs' expression must resolve to an array"),n(u(i),"'useLongestLength' must be a boolean"),a(e.defaults)&&n(m(i),"'useLongestLength' must be set to true to use 'defaults'");for(var o=0,l=0,s=r.length;l<s;l++){var c=r[l];if(h(c))return null;n(a(c),"'inputs' expression values must resolve to an array or null"),o=i?Math.max(o,c.length):Math.min(o||c.length,c.length)}for(var f=[],v=e.defaults||[],d=0;d<o;d++)!function(n){var t=r.map(function(t,e){return h(t[n])?v[e]||null:t[n]});f.push(t)}(d);return f}},On={$and:function(n,t){var e=rn(n,t,null);return m(e)&&e.every(m)},$or:function(n,t){var e=rn(n,t,null);return m(e)&&e.some(m)},$not:function(n,t){return!rn(n,t[0],null)}},kn={$cmp:function(n,t){var e=rn(n,t,null);return e[0]>e[1]?1:e[0]<e[1]?-1:0}};M(["$eq","$ne","$gt","$gte","$lt","$lte","$in","$nin"],function(n){kn[n]=function(t,e){var r=rn(t,e,null);return mn[n](r[0],r[1])}});var jn={$cond:function(t,e){var r=void 0,u=void 0,i=void 0;return a(e)?(n(3===e.length,"Invalid arguments for $cond operator"),r=e[0],u=e[1],i=e[2]):l(e)&&(r=e.if,u=e.then,i=e.else),rn(t,r,null)?rn(t,u,null):rn(t,i,null)},$switch:function(t,e){n(e.branches,"Invalid arguments for $switch operator");var r=e.branches.find(function(e){return n(e.case&&e.then,"Invalid arguments for $switch operator"),rn(t,e.case,null)});return r?rn(t,r.then,null):e.default?rn(t,e.default,null):void O("Invalid arguments for $switch operator")},$ifNull:function(t,e){n(a(e)&&2===e.length,"Invalid arguments for $ifNull operator");var r=rn(t,e,null);return null===r[0]||void 0===r[0]?r[1]:r[0]}},Nn={"%Y":["$year",4],"%m":["$month",2],"%d":["$dayOfMonth",2],"%H":["$hour",2],"%M":["$minute",2],"%S":["$second",2],"%L":["$millisecond",3],"%j":["$dayOfYear",3],"%w":["$dayOfWeek",1],"%U":["$week",2],"%%":"%"},wn={$dayOfYear:function(n,t){var e=rn(n,t,null);if(c(e)){var r=new Date(e.getFullYear(),0,0),u=e-r;return Math.round(u/864e5)}},$dayOfMonth:function(n,t){var e=rn(n,t,null);return c(e)?e.getDate():void 0},$dayOfWeek:function(n,t){var e=rn(n,t,null);return c(e)?e.getDay()+1:void 0},$year:function(n,t){var e=rn(n,t,null);return c(e)?e.getFullYear():void 0},$month:function(n,t){var e=rn(n,t,null);return c(e)?e.getMonth()+1:void 0},$week:function(n,t){var e=rn(n,t,null);e=new Date(+e),e.setHours(0,0,0),e.setDate(e.getDate()+4-(e.getDay()||7));var r=new Date(e.getFullYear(),0,1);return Math.floor(((e-r)/864e5+1)/7)},$hour:function(n,t){var e=rn(n,t,null);return c(e)?e.getUTCHours():void 0},$minute:function(n,t){var e=rn(n,t,null);return c(e)?e.getMinutes():void 0},$second:function(n,t){var e=rn(n,t,null);return c(e)?e.getSeconds():void 0},$millisecond:function(n,t){var e=rn(n,t,null);return c(e)?e.getMilliseconds():void 0},$dateToString:function(n,t){for(var e=t.format,r=rn(n,t.date,null),u=e.match(/(%%|%Y|%m|%d|%H|%M|%S|%L|%j|%w|%U)/g),i=0,o=u.length;i<o;i++){var l=Nn[u[i]],s=l;if(a(l)){var c=this[l[0]],f=l[1];s=G(c.call(this,n,r),f)}e=e.replace(u[i],s)}return e}},Mn={$literal:function(n,t){return t}},qn={$setEquals:function(n,t){var e=rn(n,t,null),r=E(e[0]),u=E(e[1]);return r.length===u.length&&r.length===S(r,u).length},$setIntersection:function(n,t){var e=rn(n,t,null);return S(e[0],e[1])},$setDifference:function(n,t){var e=rn(n,t,null);return e[0].filter($.bind(null,e[1]))},$setUnion:function(n,t){var e=rn(n,t,null);return A(e[0],e[1])},$setIsSubset:function(n,t){var e=rn(n,t,null);return S(e[0],e[1]).length===e[0].length},$anyElementTrue:function(n,t){return rn(n,t,null)[0].some(m)},$allElementsTrue:function(n,t){return rn(n,t,null)[0].every(m)}},Sn={$concat:function(n,t){var e=rn(n,t,null);return[null,void 0].some(g.bind(null,e))?null:e.join("")},$indexOfBytes:function(t,e){var r=rn(t,e,null);if(h(r[0]))return null;n(i(r[0]),"$indexOfBytes first operand must resolve to a string"),n(i(r[1]),"$indexOfBytes second operand must resolve to a string");var u=r[0],a=r[1],l=r[2],s=r[3];if(n(h(l)||o(l)&&l>=0&&Math.round(l)===l,"$indexOfBytes third operand must resolve to a non-negative integer"),l=l||0,n(h(s)||o(s)&&s>=0&&Math.round(s)===s,"$indexOfBytes fourth operand must resolve to a non-negative integer"),s=s||u.length,l>s)return-1;var c=u.substring(l,s).indexOf(a);return c>-1?c+l:c},$split:function(t,r){var u=rn(t,r,null);return n(i(u[0]),"$split requires an expression that evaluates to a string as a first argument, found: "+e(u[0])),n(i(u[1]),"$split requires an expression that evaluates to a string as a second argument, found: "+e(u[1])),u[0].split(u[1])},$strcasecmp:function(n,t){var e=rn(n,t,null);return e[0]=b(e[0])?"":e[0].toUpperCase(),e[1]=b(e[1])?"":e[1].toUpperCase(),e[0]>e[1]?1:e[0]<e[1]?-1:0},$substr:function(n,t){var e=rn(n,t,null);return i(e[0])?e[1]<0?"":e[2]<0?e[0].substr(e[1]):e[0].substr(e[1],e[2]):""},$toLower:function(n,t){var e=rn(n,t,null);return b(e)?"":e.toLowerCase()},$toUpper:function(n,t){var e=rn(n,t,null);return b(e)?"":e.toUpperCase()}},An={$map:function(t,e){var r=rn(t,e.input,null);n(a(r),"Input expression for $map must resolve to an array");var u=e.as,i=e.in,o="$"+u,l=t[o];return r.map(function(n){t[o]=n;var e=rn(t,i,null);return p(l)?delete t[o]:t[o]=l,e})},$let:function(n,t){var e=t.vars,r=t.in,u={},i=k(e);M(i,function(t){var r=rn(n,e[t],null),i="$"+t;u[i]=n[i],n[i]=r});var o=rn(n,r,null);return M(i,function(t){var e="$"+t;p(u[e])?delete n[e]:n[e]=u[e]}),o}},In=Object.assign({},_n,xn,On,kn,jn,wn,Mn,qn,Sn,An),En={aggregate:In,group:cn,pipeline:vn,projection:fn,query:yn},Cn="aggregate",Dn="group",Pn="pipeline",Rn="projection",Tn="query",Un={key:"_id"},Fn={$$ROOT:function(n,t,e){return e.root},$$CURRENT:function(n,t,e){return n}},Ln={$$KEEP:function(n){return n},$$PRUNE:function(){},$$DESCEND:function(n,t,e){if(!x(t,"$cond"))return n;var r=void 0;return M(n,function(u,i){s(u)&&(a(u)?(r=[],M(u,function(n){l(n)&&(n=an(n,t,e)),h(n)||r.push(n)})):r=an(u,t,e),h(r)?delete n[i]:n[i]=r)}),n}},Bn=k(Fn),Yn=k(Ln),Jn={query:function(n,t){return new bn(n).find(this.toJSON(),t)},aggregate:function(n){return new gn(n).run(this.toJSON())}};require("core-js/fn/array/find"),require("core-js/fn/array/find-index"),
require("core-js/fn/array/includes"),require("core-js/fn/object/assign"),require("core-js/fn/object/keys"),require("core-js/fn/object/values"),require("core-js/fn/function/bind"),require("core-js/fn/symbol/iterator");return{_internal:ln,Aggregator:gn,CollectionMixin:Jn,Cursor:$n,OP_AGGREGATE:Cn,OP_GROUP:Dn,OP_PIPELINE:Pn,OP_PROJECTION:Rn,OP_QUERY:Tn,Query:bn,VERSION:"1.3.0",addOperators:Q,aggregate:Y,find:J,remove:z}});
//# sourceMappingURL=dist/mingo.map
{
"name": "mingo",
"version": "1.2.0",
"version": "1.3.0",
"description": "JavaScript implementation of MongoDB query language",
"main": "mingo.js",
"main": "dist/mingo.js",
"module": "lib/index.js",
"scripts": {
"test": "make test",
"build": "make build"
"build": "make build",
"prepublishOnly": "make build",
"test": "make test"
},

@@ -15,7 +17,4 @@ "repository": {

"files": [
"mingo.js",
"dist/mingo.min.js",
"dist/mingo.min.js.gz",
"dist/mingo.min.map",
"Makefile",
"dist",
"lib",
"LICENSE",

@@ -28,6 +27,10 @@ "README.md",

"devDependencies": {
"dox": "0.4.4",
"dox-template": "0.1.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.0",
"backbone": ">=1.3.x",
"bson": "1.x.x",
"core-js": "2.x.x",
"gulp": ">=3.9.x",
"rollup": "^0.45.2",
"rollup-plugin-babel": "^2.7.1",
"tape": ">=4.x.x",

@@ -34,0 +37,0 @@ "uglify-js": "2.x.x"

# Mingo
JavaScript implementation of MongoDB query language
JavaScript implementation of MongoDB query language
Mingo harnesses the power of MongoDB-style queries and allows direct querying of in-memory
javascript objects in both client and server-side environments. This library is self-contained and has zero-dependencies
[![version](https://img.shields.io/npm/v/mingo.svg)](https://www.npmjs.org/package/mingo)
[![build status](https://secure.travis-ci.org/kofrasa/mingo.png)](http://travis-ci.org/kofrasa/mingo)
## Installing
## Install
```$ npm install mingo```
In browser
```html
<script type="text/javascript" src="./dist/mingo.min.js"></script>
```
## Features
- Supports Dot Notation for both '_&lt;array&gt;.&lt;index&gt;_' and '_&lt;document&gt;.&lt;field&gt;_' selectors
- Query and Projection Operators
- [Array Operators](https://docs.mongodb.com/manual/reference/operator/query-array/)
- [Comparisons Operators](https://docs.mongodb.com/manual/reference/operator/query-comparison/)
- [Element Operators](https://docs.mongodb.com/manual/reference/operator/query-element/)
- [Evaluation Operators](https://docs.mongodb.com/manual/reference/operator/query-evaluation/)
- [Logical Operators](https://docs.mongodb.com/manual/reference/operator/query-logical/)
- [Array Operators](https://docs.mongodb.com/manual/reference/operator/query-array/)
- [Comparisons Operators](https://docs.mongodb.com/manual/reference/operator/query-comparison/)
- [Element Operators](https://docs.mongodb.com/manual/reference/operator/query-element/)
- [Evaluation Operators](https://docs.mongodb.com/manual/reference/operator/query-evaluation/)
- [Logical Operators](https://docs.mongodb.com/manual/reference/operator/query-logical/)
- Aggregation Framework Operators
- [Pipeline Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/)
- [Group Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-group/)
- [Projection Operators](https://docs.mongodb.com/manual/reference/operator/projection/)
- [Arithmetic Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-arithmetic/)
- [Array Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-array/)
- [Boolean Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-boolean/)
- [Comparisons Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-comparison/)
- [Conditional Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-conditional/)
- [Date Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-date/)
- [Literal Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-literal/)
- [Set Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-set/)
- [String Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-string/)
- [Variable Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-projection/)
- [Pipeline Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/)
- [Group Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-group/)
- [Projection Operators](https://docs.mongodb.com/manual/reference/operator/projection/)
- [Arithmetic Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-arithmetic/)
- [Array Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-array/)
- [Boolean Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-boolean/)
- [Comparisons Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-comparison/)
- [Conditional Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-conditional/)
- [Date Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-date/)
- [Literal Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-literal/)
- [Set Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-set/)
- [String Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-string/)
- [Variable Operators](https://docs.mongodb.com/manual/reference/operator/aggregation-projection/)
- Support for adding custom operators

@@ -44,2 +36,3 @@ - Match against user-defined types

- [`$$ROOT`,`$$CURRENT`,`$$DESCEND`,`$$PRUNE`,`$$KEEP`](https://docs.mongodb.com/manual/reference/aggregation-variables/)
- Fully ES6 module compatible
- Support integrating with custom collections via mixin

@@ -52,18 +45,37 @@ - Query filter and projection streaming. See [mingo-stream](https://github.com/kofrasa/mingo-stream)

## Usage
On the server side
```js
// Use as es6 module
import mingo from 'mingo'
var Mingo = require('mingo');
// or just access *Mingo* global in browser
// or vanilla nodeJS
var mingo = require('mingo')
```
For the browser
```
// minified UMD module
<script type="text/javascript" src="./dist/mingo.min.js"></script>
// or gzipped UMD module
<script type="text/javascript" src="./dist/mingo.min.js.gz"></script>
```
Tiny configuration if needed
```js
// setup the key field for your collection
Mingo.setup({
mingo.setup({
key: '_id' // default
});
## Using query object to test objects
// create a query with criteria
// find all grades for homework with score >= 50
var query = new Mingo.Query({
let query = new mingo.Query({
type: "homework",
score: { $gte: 50 }
});
query.test(someObject)
```

@@ -76,6 +88,6 @@

// filter collection with find()
var cursor = query.find(collection);
let cursor = query.find(collection);
// shorthand with query criteria
// cursor = Mingo.find(collection, criteria);
// cursor = mingo.find(collection, criteria);

@@ -102,3 +114,3 @@ // sort, skip and limit by chaining

// Filter non-matched objects (
var result = query.remove(collection);
console.log(query.remove(collection));
```

@@ -108,3 +120,3 @@

```js
var agg = new Mingo.Aggregator([
let agg = new mingo.Aggregator([
{'$match': { "type": "homework"}},

@@ -115,12 +127,12 @@ {'$group':{'_id':'$student_id', 'score':{$min:'$score'}}},

var result = agg.run(collection);
let result = agg.run(collection);
// shorthand
result = Mingo.aggregate(
collection,
[
{'$match': { "type": "homework"}},
{'$group':{'_id':'$student_id', 'score':{$min:'$score'}}},
{'$sort':{'_id': 1, 'score': 1}}
]
result = mingo.aggregate(
collection,
[
{'$match': { "type": "homework"}},
{'$group':{'_id':'$student_id', 'score':{$min:'$score'}}},
{'$sort':{'_id': 1, 'score': 1}}
]
);

@@ -132,6 +144,6 @@ ```

// using Backbone.Collection as an example (any user-defined object will do)
var Grades = Backbone.Collection.extend(Mingo.CollectionMixin);
let Grades = Backbone.Collection.extend(mingo.CollectionMixin);
// `collection` is an array of objects
var grades = new Grades(collection);
let grades = new Grades(collection);

@@ -141,3 +153,3 @@ // find students with grades less than 50 in homework or quiz

cursor = grades.query({
$or: [{type: "quiz", score: {$lt: 50}}, {type: "homework", score: {$lt: 50}}]
$or: [{type: "quiz", score: {$lt: 50}}, {type: "homework", score: {$lt: 50}}]
}).sort({score: 1, type: -1}).limit(10);

@@ -155,9 +167,15 @@

## Why?
- Born out of a real need
- Alternative to writing a lot of custom code for transforming collections of JSON objects
- Quick validation of MongoDB queries without the need for a database
- MongoDB query language is among the best in the market and is well documented
- Finally, because queries are better than me and perhaps you too :)
## Contributing
* Submit pull requests to the [development](https://github.com/kofrasa/mingo/tree/development) branch
* Before you submit pull requests
* Unstage files under **_dist/_**
* Squash changes into one commit
* Squash changes into one commit
* Run `make` to ensure build and tests pass
## License
MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc