Comparing version 0.6.3 to 0.6.4
@@ -6,25 +6,19 @@ Changelog | ||
v0.6.3 / 2015-12-27 | ||
------------------- | ||
## v0.6.4 / 2016-05-19 | ||
- Support matching against user-defined types. See [issue#22](https://github.com/kofrasa/mingo/issues/22) | ||
## v0.6.3 / 2015-12-27 | ||
- Fixed numeric aggregation over undefined values. See [issues#21](https://github.com/kofrasa/mingo/issues/21) | ||
v0.6.2 / 2015-11-17 | ||
------------------- | ||
## v0.6.2 / 2015-11-17 | ||
- Fixed erroneous cloning of objects. See [issue#20](https://github.com/kofrasa/mingo/pull/20) | ||
v0.6.1 / 2015-09-20 | ||
------------------- | ||
## v0.6.1 / 2015-09-20 | ||
- Fixed matching nested array fields without specifying index. See [issue#19](https://github.com/kofrasa/mingo/issues/19) | ||
- Added `VERSION` global field | ||
v0.6.0 / 2015-05-28 | ||
------------------- | ||
## v0.6.0 / 2015-05-28 | ||
- Added `$dateToString` aggregation operator | ||
v0.5.0 / 2015-04-29 | ||
------------------- | ||
## v0.5.0 / 2015-04-29 | ||
- Added support for extending operators via `Mingo.addOperators` | ||
@@ -31,0 +25,0 @@ - Added `bower.json` |
34
mingo.js
@@ -1,3 +0,3 @@ | ||
// Mingo.js 0.6.3 | ||
// Copyright (c) 2015 Francis Asante <kofrasa@gmail.com> | ||
// Mingo.js 0.6.4 | ||
// Copyright (c) 2016 Francis Asante <kofrasa@gmail.com> | ||
// MIT | ||
@@ -41,3 +41,3 @@ | ||
var primitives = [ | ||
_.isString, _.isBoolean, _.isNumber, _.isDate, _.isNull, _.isRegExp | ||
_.isString, _.isBoolean, _.isNumber, _.isDate, _.isNull, _.isRegExp, _.isUndefined | ||
]; | ||
@@ -54,2 +54,8 @@ | ||
var NATIVE_CONSTRUCTORS = ["Object", "Array"]; | ||
// primitives and user-defined types | ||
function isSimpleType(value) { | ||
return isPrimitive(value) || !_.contains(NATIVE_CONSTRUCTORS, value.constructor.name); | ||
} | ||
/** | ||
@@ -63,3 +69,3 @@ * Simplify expression for easy evaluation with query operators map | ||
// normalized primitives | ||
if (isPrimitive(expr)) { | ||
if (isSimpleType(expr)) { | ||
return _.isRegExp(expr) ? {"$regex": expr} : {"$eq": expr}; | ||
@@ -138,3 +144,3 @@ } | ||
for (var field in this._criteria) { | ||
if (this._criteria.hasOwnProperty(field)) { | ||
if (_.has(this._criteria, field)) { | ||
var expr = this._criteria[field]; | ||
@@ -147,3 +153,3 @@ if (_.contains(['$and', '$or', '$nor', '$where'], field)) { | ||
for (var op in expr) { | ||
if (expr.hasOwnProperty(op)) { | ||
if (_.has(expr, op)) { | ||
this._processOperator(field, op, expr[op]); | ||
@@ -685,3 +691,3 @@ } | ||
for (var key in expr) { | ||
if (expr.hasOwnProperty(key)) { | ||
if (_.has(expr, key)) { | ||
obj[key] = accumulate(partitions.groups[i], key, expr[key]); | ||
@@ -766,3 +772,3 @@ } | ||
} else if (subExpr === 1 || subExpr === true) { | ||
newValue = _.result(obj, key); | ||
newValue = getValue(obj, key); | ||
} else if (_.isObject(subExpr)) { | ||
@@ -1018,3 +1024,3 @@ var operator = _.keys(subExpr); | ||
// flatten to reach nested values. fix for https://github.com/kofrasa/mingo/issues/19 | ||
a = _.flatten(_.isArray(a) ? a : [a]); | ||
a = _.flatten([a]); | ||
a = _.find(a, function (val) { | ||
@@ -1368,3 +1374,3 @@ return _.isEqual(val, b); | ||
}, | ||
/** | ||
@@ -1379,3 +1385,3 @@ * Returns the highest value in a group. | ||
var obj = _.max(collection, function (obj) { | ||
return computeValue(obj, expr, null); | ||
return computeValue(obj, expr, null); | ||
}); | ||
@@ -2163,3 +2169,3 @@ return computeValue(obj, expr, null); | ||
for (var key in expr) { | ||
if (expr.hasOwnProperty(key)) { | ||
if (_.has(expr, key)) { | ||
result[key] = accumulate(collection, key, expr[key]); | ||
@@ -2208,3 +2214,3 @@ // must run ONLY one group operator per expression | ||
// check and return value if already in a resolved state | ||
if (isPrimitive(expr)) { | ||
if (isSimpleType(expr)) { | ||
return expr; | ||
@@ -2218,3 +2224,3 @@ } else if (_.isArray(expr)) { | ||
for (var key in expr) { | ||
if (expr.hasOwnProperty(key)) { | ||
if (_.has(expr, key)) { | ||
result[key] = computeValue(obj, expr[key], key); | ||
@@ -2221,0 +2227,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(r,n){"use strict";function t(r){for(var n=0;n<g.length;n++)if(g[n](r))return!0;return!1}function e(r){if(t(r))return h.isRegExp(r)?{$regex:r}:{$eq:r};if(h.isObject(r)){var n=h.keys(r),e=0===h.intersection(s(Q),n).length;if(e)return{$eq:r};if(h.contains(n,"$regex")){var i=r.$regex,u=r.$options||"",o="";h.isString(i)&&(o+=i.ignoreCase||u.indexOf("i")>=0?"i":"",o+=i.multiline||u.indexOf("m")>=0?"m":"",o+=i.global||u.indexOf("g")>=0?"g":"",i=new RegExp(i,o)),r.$regex=i,delete r.$options}}return r}function i(r,n){return h.result(r,n)}function u(r,t){if(!t)return n;for(var e,o=t.split("."),s=r,a=0;a<o.length;a++){if(e=null===o[a].match(/^\d+$/),e&&h.isArray(s)){var f=[];h.each(s,function(r){f.push(u(r,o[a]))}),s=f}else s=i(s,o[a]);if(s===n)break}return s}function o(r,n){return new Array(Math.max(n-String(r).length+1,0)).join("0")+r}function s(r){return h.keys(Y[r])}function a(r,n){var t={keys:[],groups:[]};if(h.each(r,function(r){var e=n(r),i=-1;if(h.isObject(e)){for(var u=0;u<t.keys.length;u++)if(h.isEqual(e,t.keys[u])){i=u;break}}else i=h.indexOf(t.keys,e);i>-1?t.groups[i].push(r):(t.keys.push(e),t.groups.push([r]))}),t.keys.length!==t.groups.length)throw new Error("assert groupBy(): keys.length !== groups.length");return t}function f(r,t,e){if(h.contains(s(C),t))return O[t](r,e);if(h.isObject(e)){var i={};for(var u in e)if(e.hasOwnProperty(u)&&(i[u]=f(r,u,e[u]),h.contains(s(C),u))){if(i=i[u],h.keys(e).length>1)throw new Error("Invalid $group expression '"+JSON.stringify(e)+"'");break}return i}return n}function c(r,n,e){if(h.contains(s(P),e))return U[e](r,n);if(h.isString(n)&&n.length>0&&"$"===n[0])return u(r,n.slice(1));var i;if(t(n))return n;if(h.isArray(n))i=h.map(n,function(n){return c(r,n,null)});else if(h.isObject(n)){i={};for(var o in n)if(n.hasOwnProperty(o)&&(i[o]=c(r,n[o],o),h.contains(s(P),o))){if(i=i[o],h.keys(n).length>1)throw new Error("Invalid aggregation expression '"+JSON.stringify(n)+"'");break}}return i}var l,h,p={};p.VERSION="0.6.3",null!=r&&(l=r.Mingo),p.noConflict=function(){return r.Mingo=l,p};var y="undefined"!=typeof module&&"undefined"!=typeof require;y?("undefined"!=typeof module&&(module.exports=p),h=require("underscore")):(r.Mingo=p,h=r._);var g=[h.isString,h.isBoolean,h.isNumber,h.isDate,h.isNull,h.isRegExp],v={key:"_id"};if(p.setup=function(r){h.extend(v,r||{})},p.Query=function(r,n){return this instanceof p.Query?(this._criteria=r,this._projection=n,this._compiled=[],void this._compile()):new p.Query(r,n)},p.Query.prototype={_compile:function(){if(!h.isEmpty(this._criteria)){if(h.isArray(this._criteria)||h.isFunction(this._criteria)||!h.isObject(this._criteria))throw new Error("Invalid type for criteria");for(var r in this._criteria)if(this._criteria.hasOwnProperty(r)){var n=this._criteria[r];if(h.contains(["$and","$or","$nor","$where"],r))this._processOperator(r,r,n);else{n=e(n);for(var t in n)n.hasOwnProperty(t)&&this._processOperator(r,t,n[t])}}}},_processOperator:function(r,n,t){if(!h.contains(s(Q),n))throw new Error("Invalid query operator '"+n+"' detected");this._compiled.push(w[n](r,t))},test:function(r){for(var n=0;n<this._compiled.length;n++)if(!this._compiled[n].test(r))return!1;return!0},find:function(r,n){return new p.Cursor(r,this,n)},remove:function(r){for(var n=[],t=0;t<r.length;t++)this.test(r[t])||n.push(r[t]);return n}},y){var $=require("stream").Transform,d=require("util");p.Query.prototype.stream=function(r){return new p.Stream(this,r)},p.Stream=function(r,n){return this instanceof p.Stream?(n=n||{},h.extend(n,{objectMode:!0}),$.call(this,n),void(this._query=r)):new p.Stream(r,n)},d.inherits(p.Stream,$),p.Stream.prototype._transform=function(r,n,t){if(h.isObject(r)&&this._query.test(r))if(h.isEmpty(this._query._projection))this.push(r);else{var e=new p.Cursor([r],this._query);e.hasNext()&&this.push(e.next())}t()}}p.Cursor=function(r,n,t){return this instanceof p.Cursor?(this._query=n,this._collection=r,this._projection=t||n._projection,this._operators={},this._result=!1,void(this._position=0)):new p.Cursor(r,n,t)},p.Cursor.prototype={_fetch:function(){var r=this;if(this._result!==!1)return this._result;if(h.isObject(this._projection)&&h.extend(this._operators,{$project:this._projection}),!h.isArray(this._collection))throw new Error("Input collection is not of valid type. Must be an Array.");this._result=h.filter(this._collection,this._query.test,this._query);var n=[];if(h.each(["$sort","$skip","$limit","$project"],function(t){h.has(r._operators,t)&&n.push(h.pick(r._operators,t))}),n.length>0){var t=new p.Aggregator(n);this._result=t.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(r){return h.extend(this._operators,{$skip:r}),this},limit:function(r){return h.extend(this._operators,{$limit:r}),this},sort:function(r){return h.extend(this._operators,{$sort:r}),this},next:function(){return this.hasNext()?this._fetch()[this._position++]:null},hasNext:function(){return this.count()>this._position},max:function(r){return O.$max(this._fetch(),r)},min:function(r){return O.$min(this._fetch(),r)},map:function(r){return h.map(this._fetch(),r)},forEach:function(r){h.each(this._fetch(),r)}},p.Aggregator=function(r){return this instanceof p.Aggregator?void(this._operators=r):new p.Aggregator(r)},p.Aggregator.prototype={run:function(r,n){if(!h.isEmpty(this._operators))for(var t=0;t<this._operators.length;t++){var e=this._operators[t],i=h.keys(e);if(1!=i.length||!h.contains(s(R),i[0]))throw new Error("Invalid aggregation operator '"+i+"'");i=i[0],r=n instanceof p.Query?m[i].call(n,r,e[i]):m[i](r,e[i])}return r}},p.find=function(r,n,t){return new p.Query(n).find(r,t)},p.remove=function(r,n){return new p.Query(n).remove(r)},p.aggregate=function(r,n){if(!h.isArray(n))throw new Error("Aggregation pipeline must be an array");return new p.Aggregator(n).run(r)},p.addOperators=function(r,n){var t=n({resolve:u,computeValue:c,ops:s,key:function(){return v.key}});if(!h.contains([P,C,R,T,Q],r))throw new Error("Could not identify type '"+r+"'");var e=s(r);h.each(h.keys(t),function(n){if(!/^\$\w+$/.test(n))throw new Error("Invalid operator name '"+n+"'");if(h.contains(e,n))throw new Error("Operator "+n+" is already defined for "+r+" operators")});var i={};switch(r){case Q:h.each(h.keys(t),function(r){i[r]=function(n,t){return function(e,i){return{test:function(o){var s=u(o,e),a=n.call(t,e,s,i);if(h.isBoolean(a))return a;if(a instanceof p.Query)return a.test(o);throw new Error("Invalid return type for '"+r+"'. Must return a Boolean or Mingo.Query")}}}}(t[r],t)});break;case T:h.each(h.keys(t),function(r){i[r]=function(r,n){return function(t,e,i){var o=u(t,i);return r.call(n,i,o,e)}}(t[r],t)});break;default:h.each(h.keys(t),function(r){i[r]=function(r,n){return function(){var t=Array.prototype.slice.call(arguments);return r.apply(n,t)}}(t[r],t)})}h.extend(Y[r],i)},p.CollectionMixin={query:function(r,n){return p.find(this.toJSON(),r,n)},aggregate:function(r){var n=[this.toJSON(),r];return p.aggregate.apply(null,n)}};var m={$group:function(r,n){var t=n[v.key],e=a(r,function(r){return c(r,t,t)}),i=[];return n=h.omit(n,v.key),h.each(e.keys,function(r,t){var u={};h.isUndefined(r)||(u[v.key]=r);for(var o in n)n.hasOwnProperty(o)&&(u[o]=f(e.groups[t],o,n[o]));i.push(u)}),i},$match:function(r,n){return new p.Query(n).find(r).all()},$project:function(r,n){if(h.isEmpty(n))return r;var t=[],e=h.keys(n),i=!1;if(h.contains(e,v.key)){var u=n[v.key];(0===u||u===!1)&&(e=h.without(e,v.key),h.isEmpty(e)&&(i=!0))}else e.push(v.key);for(var o=0;o<r.length;o++){var a=r[o],f={},l=!1,p=!1,y=[];i&&y.push(v.key),h.each(e,function(r){var t,e=n[r];if(r!==v.key&&0===e&&(p=!0),r===v.key&&h.isEmpty(e))t=a[r];else if(h.isString(e))t=c(a,e,r);else if(1===e||e===!0)t=h.result(a,r);else if(h.isObject(e)){var i=h.keys(e);if(i=i.length>1?!1:i[0],i!==!1&&h.contains(s(T),i)){var u=k[i](a,e[i],r);h.isUndefined(u)||(t=u),"$slice"==i&&(l=!0)}else t=c(a,e,r)}else y.push(r);h.isUndefined(t)||(f[r]=t)}),(l||p||i)&&(f=h.defaults(f,h.omit(a,y))),t.push(f)}return t},$limit:function(r,n){return h.first(r,n)},$skip:function(r,n){return h.rest(r,n)},$unwind:function(r,n){for(var t=[],e=n.substr(1),u=0;u<r.length;u++){var o=r[u],s=i(o,e);if(!h.isArray(s))throw new Error("Target field '"+e+"' is not of type Array.");h.each(s,function(r){var n=h.clone(o);n[e]=r,t.push(n)})}return t},$sort:function(r,n){if(!h.isEmpty(n)&&h.isObject(n)){var t=h.keys(n);t.reverse().forEach(function(t){var e=[],i=h.groupBy(r,function(r){var n=u(r,t);return e.push(n),n});e=h.sortBy(h.uniq(e),function(r){return r}),-1===n[t]&&e.reverse(),r=[],h.each(e,function(n){Array.prototype.push.apply(r,i[n])})})}return r}},w={},_={$and:function(r,n){if(!h.isArray(n))throw new Error("Invalid expression for $and criteria");var t=[];return h.each(n,function(r){t.push(new p.Query(r))}),{test:function(r){for(var n=0;n<t.length;n++)if(!t[n].test(r))return!1;return!0}}},$or:function(r,n){if(!h.isArray(n))throw new Error("Invalid expression for $or criteria");var t=[];return h.each(n,function(r){t.push(new p.Query(r))}),{test:function(r){for(var n=0;n<t.length;n++)if(t[n].test(r))return!0;return!1}}},$nor:function(r,n){if(!h.isArray(n))throw new Error("Invalid expression for $nor criteria");var t=this.$or("$or",n);return{test:function(r){return!t.test(r)}}},$not:function(r,n){var t={};t[r]=e(n);var i=new p.Query(t);return{test:function(r){return!i.test(r)}}},$where:function(r,n){return h.isFunction(n)||(n=new Function("return "+n+";")),{test:function(r){return n.call(r)===!0}}}};h.extend(w,_);var E={$eq:function(r,t){return r=h.flatten(h.isArray(r)?r:[r]),r=h.find(r,function(r){return h.isEqual(r,t)}),r!==n},$ne:function(r,n){return!this.$eq(r,n)},$in:function(r,n){return r=h.isArray(r)?r:[r],h.intersection(r,n).length>0},$nin:function(r,n){return h.isUndefined(r)||!this.$in(r,n)},$lt:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return t>r}),r!==n},$lte:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return t>=r}),r!==n},$gt:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return r>t}),r!==n},$gte:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return r>=t}),r!==n},$mod:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return h.isNumber(r)&&h.isArray(t)&&2===t.length&&r%t[0]===t[1]}),r!==n},$regex:function(r,t){return r=h.isArray(r)?r:[r],r=h.find(r,function(r){return h.isString(r)&&h.isRegExp(t)&&!!r.match(t)}),r!==n},$exists:function(r,n){return n===!1&&h.isUndefined(r)||n===!0&&!h.isUndefined(r)},$all:function(r,n){var t=this,e=!1;if(h.isArray(r)&&h.isArray(n))for(var i=0;i<n.length;i++){if(!h.isObject(n[i])||!h.contains(h.keys(n[i]),"$elemMatch"))return h.intersection(n,r).length===n.length;e=e||t.$elemMatch(r,n[i].$elemMatch)}return e},$size:function(r,n){return h.isArray(r)&&h.isNumber(n)&&r.length===n},$elemMatch:function(r,n){if(h.isArray(r)&&!h.isEmpty(r))for(var t=new p.Query(n),e=0;e<r.length;e++)if(t.test(r[e]))return!0;return!1},$type:function(r,n){switch(n){case 1:return h.isNumeric(r)&&-1!==(r+"").indexOf(".");case 2:case 5:return h.isString(r);case 3:return h.isObject(r);case 4:return h.isArray(r);case 8:return h.isBoolean(r);case 9:return h.isDate(r);case 10:return h.isNull(r);case 11:return h.isRegExp(r);case 16:return h.isNumeric(r)&&2147483647>=r&&-1===(r+"").indexOf(".");case 18:return h.isNumeric(r)&&r>2147483647&&0x8000000000000000>=r&&-1===(r+"").indexOf(".");default:return!1}}};h.each(h.keys(E),function(r){w[r]=function(r,n){return function(t,e){return{test:function(i){var o=u(i,t);return r.call(n,o,e)}}}}(E[r],E)});var k={$:function(){throw new Error("$ not implemented")},$elemMatch:function(r,t,e){var i=u(r,e),o=new p.Query(t);if(h.isUndefined(i)||!h.isArray(i))return n;for(var s=0;s<i.length;s++)if(o.test(i[s]))return[i[s]];return n},$slice:function(r,n,t){var e=u(r,t);if(!h.isArray(e))return e;if(h.isArray(n)){var i=n[0]<0?e.length+n[0]:n,o=i+n[1];n=[i,o]}else{if(!h.isNumber(n))throw new Error("Invalid type for $slice operator");n=0>n?[n]:[0,n]}return Array.prototype.slice.apply(e,n)}},O={$addToSet:function(r,n){var t=h.map(r,function(r){return c(r,n,null)});return h.uniq(t)},$sum:function(r,n){return h.isArray(r)?h.isNumber(n)?r.length*n:h.reduce(r,function(r,t){var e=c(t,n,null);return h.isNumber(e)?r+e:r},0):0},$max:function(r,n){var t=h.max(r,function(r){return c(r,n,null)});return c(t,n,null)},$min:function(r,n){var t=h.min(r,function(r){return c(r,n,null)});return c(t,n,null)},$avg:function(r,n){return this.$sum(r,n)/(r.length||1)},$push:function(r,n){return h.map(r,function(r){return c(r,n,null)})},$first:function(r,t){return r.length>0?c(r[0],t):n},$last:function(r,t){return r.length>0?c(r[r.length-1],t):n}},A={$add:function(r,n){var t=c(r,n,null);return h.reduce(t,function(r,n){return r+n},0)},$subtract:function(r,n){var t=c(r,n,null);return t[0]-t[1]},$divide:function(r,n){var t=c(r,n,null);return t[0]/t[1]},$multiply:function(r,n){var t=c(r,n,null);return h.reduce(t,function(r,n){return r*n},1)},$mod:function(r,n){var t=c(r,n,null);return t[0]%t[1]}},x={$concat:function(r,t){var e=c(r,t,null);return h.contains(e,null)||h.contains(e,n)?null:e.join("")},$strcasecmp:function(r,n){var t=c(r,n,null);return t[0]=h.isEmpty(t[0])?"":t[0].toUpperCase(),t[1]=h.isEmpty(t[1])?"":t[1].toUpperCase(),t[0]>t[1]?1:t[0]<t[1]?-1:0},$substr:function(r,n){var t=c(r,n,null);return h.isString(t[0])?t[1]<0?"":t[2]<0?t[0].substr(t[1]):t[0].substr(t[1],t[2]):""},$toLower:function(r,n){var t=c(r,n,null);return h.isEmpty(t)?"":t.toLowerCase()},$toUpper:function(r,n){var t=c(r,n,null);return h.isEmpty(t)?"":t.toUpperCase()}},b={$dayOfYear:function(r,t){var e=c(r,t,null);if(h.isDate(e)){var i=new Date(e.getFullYear(),0,0),u=e-i,o=864e5;return Math.round(u/o)}return n},$dayOfMonth:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getDate():n},$dayOfWeek:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getDay()+1:n},$year:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getFullYear():n},$month:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getMonth()+1:n},$week:function(r,n){var t=c(r,n,null);t=new Date(+t),t.setHours(0,0,0),t.setDate(t.getDate()+4-(t.getDay()||7));var e=new Date(t.getFullYear(),0,1);return Math.floor(((t-e)/864e5+1)/7)},$hour:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getHours():n},$minute:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getMinutes():n},$second:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getSeconds():n},$millisecond:function(r,t){var e=c(r,t,null);return h.isDate(e)?e.getMilliseconds():n},$dateToString:function(r,n){for(var t=n.format,e=c(r,n.date,null),i=t.match(/(%%|%Y|%m|%d|%H|%M|%S|%L|%j|%w|%U)/g),u=0,s=i.length;s>u;u++){var a=B[i[u]],f=a;if(h.isArray(a)){var l=this[a[0]],p=a[1];f=o(l.call(this,r,e),p)}t=t.replace(i[u],f)}return t}},j={$setEquals:function(r,n){var t=c(r,n,null),e=h.uniq(t[0]),i=h.uniq(t[1]);return e.length!==i.length?!1:0==h.difference(e,i).length},$setIntersection:function(r,n){var t=c(r,n,null);return h.intersection(t[0],t[1])},$setDifference:function(r,n){var t=c(r,n,null);return h.difference(t[0],t[1])},$setUnion:function(r,n){var t=c(r,n,null);return h.union(t[0],t[1])},$setIsSubset:function(r,n){var t=c(r,n,null);return h.intersection(t[0],t[1]).length===t[0].length},$anyElementTrue:function(r,n){for(var t=c(r,n,null)[0],e=0;e<t.length;e++)if(t[e])return!0;return!1},$allElementsTrue:function(r,n){for(var t=c(r,n,null)[0],e=0;e<t.length;e++)if(!t[e])return!1;return!0}},q={$cond:function(r,n){var t,e,i;if(h.isArray(n)){if(3!=n.length)throw new Error("Invalid arguments for $cond operator");t=n[0],e=n[1],i=n[2]}else h.isObject(n)&&(t=n["if"],e=n.then,i=n["else"]);var u=c(r,t,null);return u?c(r,e,null):c(r,i,null)},$ifNull:function(r,t){if(!h.isArray(t)||2!=t.length)throw new Error("Invalid arguments for $ifNull operator");var e=c(r,t,null);return null===e[0]||e[0]===n?e[1]:e[0]}},S={$cmp:function(r,n){var t=c(r,n,null);return t[0]>t[1]?1:t[0]<t[1]?-1:0}};h.each(["$eq","$ne","$gt","$gte","$lt","$lte"],function(r){S[r]=function(n,t){var e=c(n,t,null);return E[r](e[0],e[1])}});var M={$size:function(r,t){var e=c(r,t,null);return h.isArray(e)?e.length:n}},N={$literal:function(r,n){return n}},I={$map:function(r,n){var t=c(r,n.input,null);if(!h.isArray(t))throw new Error("Input expression for $map must resolve to an array");var e=n.as,i=n["in"],u="$"+e,o=r[u];return h.map(t,function(n){r[u]=n;var t=c(r,i,null);return h.isUndefined(o)?delete r[u]:r[u]=o,t})},$let:function(r,n){var t=n.vars,e=n["in"],i={},u=h.keys(t);h.each(u,function(n){var e=c(r,t[n],null),u="$"+n;i[u]=r[u],r[u]=e});var o=c(r,e,null);return h.each(u,function(n){var t="$"+n;h.isUndefined(i[t])?delete r[t]:r[t]=i[t]}),o}},D={$and:function(r,n){var t=c(r,n,null);return h.every(t)},$or:function(r,n){var t=c(r,n,null);return h.some(t)},$not:function(r,n){return!c(r,n[0],null)}},U=h.extend({},M,A,D,S,q,b,N,j,x,I),Q=p.OP_QUERY="query",C=p.OP_GROUP="group",P=p.OP_AGGREGATE="aggregate",R=p.OP_PIPELINE="pipeline",T=p.OP_PROJECTION="projection",Y={aggregate:U,group:O,pipeline:m,projection:k,query:w},B={"%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],"%%":"%"}}(this); | ||
!function(r,n){"use strict";function t(r){for(var n=0;n<v.length;n++)if(v[n](r))return!0;return!1}function e(r){return t(r)||!p.contains($,r.constructor.name)}function i(r){if(e(r))return p.isRegExp(r)?{$regex:r}:{$eq:r};if(p.isObject(r)){var n=p.keys(r),t=0===p.intersection(a(R),n).length;if(t)return{$eq:r};if(p.contains(n,"$regex")){var i=r.$regex,u=r.$options||"",o="";p.isString(i)&&(o+=i.ignoreCase||u.indexOf("i")>=0?"i":"",o+=i.multiline||u.indexOf("m")>=0?"m":"",o+=i.global||u.indexOf("g")>=0?"g":"",i=new RegExp(i,o)),r.$regex=i,delete r.$options}}return r}function u(r,n){return p.result(r,n)}function o(r,t){if(!t)return n;for(var e,i=t.split("."),s=r,a=0;a<i.length;a++){if(e=null===i[a].match(/^\d+$/),e&&p.isArray(s)){var c=[];p.each(s,function(r){c.push(o(r,i[a]))}),s=c}else s=u(s,i[a]);if(s===n)break}return s}function s(r,n){return new Array(Math.max(n-String(r).length+1,0)).join("0")+r}function a(r){return p.keys(F[r])}function c(r,n){var t={keys:[],groups:[]};if(p.each(r,function(r){var e=n(r),i=-1;if(p.isObject(e)){for(var u=0;u<t.keys.length;u++)if(p.isEqual(e,t.keys[u])){i=u;break}}else i=p.indexOf(t.keys,e);i>-1?t.groups[i].push(r):(t.keys.push(e),t.groups.push([r]))}),t.keys.length!==t.groups.length)throw new Error("assert groupBy(): keys.length !== groups.length");return t}function f(r,t,e){if(p.contains(a(P),t))return O[t](r,e);if(p.isObject(e)){var i={};for(var u in e)if(p.has(e,u)&&(i[u]=f(r,u,e[u]),p.contains(a(P),u))){if(i=i[u],p.keys(e).length>1)throw new Error("Invalid $group expression '"+JSON.stringify(e)+"'");break}return i}return n}function l(r,n,t){if(p.contains(a(T),t))return C[t](r,n);if(p.isString(n)&&n.length>0&&"$"===n[0])return o(r,n.slice(1));var i;if(e(n))return n;if(p.isArray(n))i=p.map(n,function(n){return l(r,n,null)});else if(p.isObject(n)){i={};for(var u in n)if(p.has(n,u)&&(i[u]=l(r,n[u],u),p.contains(a(T),u))){if(i=i[u],p.keys(n).length>1)throw new Error("Invalid aggregation expression '"+JSON.stringify(n)+"'");break}}return i}var h,p,y={};y.VERSION="0.6.3",null!=r&&(h=r.Mingo),y.noConflict=function(){return r.Mingo=h,y};var g="undefined"!=typeof module&&"undefined"!=typeof require;g?("undefined"!=typeof module&&(module.exports=y),p=require("underscore")):(r.Mingo=y,p=r._);var v=[p.isString,p.isBoolean,p.isNumber,p.isDate,p.isNull,p.isRegExp,p.isUndefined],$=["Object","Array"],d={key:"_id"};if(y.setup=function(r){p.extend(d,r||{})},y.Query=function(r,n){return this instanceof y.Query?(this._criteria=r,this._projection=n,this._compiled=[],void this._compile()):new y.Query(r,n)},y.Query.prototype={_compile:function(){if(!p.isEmpty(this._criteria)){if(p.isArray(this._criteria)||p.isFunction(this._criteria)||!p.isObject(this._criteria))throw new Error("Invalid type for criteria");for(var r in this._criteria)if(p.has(this._criteria,r)){var n=this._criteria[r];if(p.contains(["$and","$or","$nor","$where"],r))this._processOperator(r,r,n);else{n=i(n);for(var t in n)p.has(n,t)&&this._processOperator(r,t,n[t])}}}},_processOperator:function(r,n,t){if(!p.contains(a(R),n))throw new Error("Invalid query operator '"+n+"' detected");this._compiled.push(E[n](r,t))},test:function(r){for(var n=0;n<this._compiled.length;n++)if(!this._compiled[n].test(r))return!1;return!0},find:function(r,n){return new y.Cursor(r,this,n)},remove:function(r){for(var n=[],t=0;t<r.length;t++)this.test(r[t])||n.push(r[t]);return n}},g){var m=require("stream").Transform,w=require("util");y.Query.prototype.stream=function(r){return new y.Stream(this,r)},y.Stream=function(r,n){return this instanceof y.Stream?(n=n||{},p.extend(n,{objectMode:!0}),m.call(this,n),void(this._query=r)):new y.Stream(r,n)},w.inherits(y.Stream,m),y.Stream.prototype._transform=function(r,n,t){if(p.isObject(r)&&this._query.test(r))if(p.isEmpty(this._query._projection))this.push(r);else{var e=new y.Cursor([r],this._query);e.hasNext()&&this.push(e.next())}t()}}y.Cursor=function(r,n,t){return this instanceof y.Cursor?(this._query=n,this._collection=r,this._projection=t||n._projection,this._operators={},this._result=!1,void(this._position=0)):new y.Cursor(r,n,t)},y.Cursor.prototype={_fetch:function(){var r=this;if(this._result!==!1)return this._result;if(p.isObject(this._projection)&&p.extend(this._operators,{$project:this._projection}),!p.isArray(this._collection))throw new Error("Input collection is not of valid type. Must be an Array.");this._result=p.filter(this._collection,this._query.test,this._query);var n=[];if(p.each(["$sort","$skip","$limit","$project"],function(t){p.has(r._operators,t)&&n.push(p.pick(r._operators,t))}),n.length>0){var t=new y.Aggregator(n);this._result=t.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(r){return p.extend(this._operators,{$skip:r}),this},limit:function(r){return p.extend(this._operators,{$limit:r}),this},sort:function(r){return p.extend(this._operators,{$sort:r}),this},next:function(){return this.hasNext()?this._fetch()[this._position++]:null},hasNext:function(){return this.count()>this._position},max:function(r){return O.$max(this._fetch(),r)},min:function(r){return O.$min(this._fetch(),r)},map:function(r){return p.map(this._fetch(),r)},forEach:function(r){p.each(this._fetch(),r)}},y.Aggregator=function(r){return this instanceof y.Aggregator?void(this._operators=r):new y.Aggregator(r)},y.Aggregator.prototype={run:function(r,n){if(!p.isEmpty(this._operators))for(var t=0;t<this._operators.length;t++){var e=this._operators[t],i=p.keys(e);if(1!=i.length||!p.contains(a(Y),i[0]))throw new Error("Invalid aggregation operator '"+i+"'");i=i[0],r=n instanceof y.Query?_[i].call(n,r,e[i]):_[i](r,e[i])}return r}},y.find=function(r,n,t){return new y.Query(n).find(r,t)},y.remove=function(r,n){return new y.Query(n).remove(r)},y.aggregate=function(r,n){if(!p.isArray(n))throw new Error("Aggregation pipeline must be an array");return new y.Aggregator(n).run(r)},y.addOperators=function(r,n){var t=n({resolve:o,computeValue:l,ops:a,key:function(){return d.key}});if(!p.contains([T,P,Y,B,R],r))throw new Error("Could not identify type '"+r+"'");var e=a(r);p.each(p.keys(t),function(n){if(!/^\$\w+$/.test(n))throw new Error("Invalid operator name '"+n+"'");if(p.contains(e,n))throw new Error("Operator "+n+" is already defined for "+r+" operators")});var i={};switch(r){case R:p.each(p.keys(t),function(r){i[r]=function(n,t){return function(e,i){return{test:function(u){var s=o(u,e),a=n.call(t,e,s,i);if(p.isBoolean(a))return a;if(a instanceof y.Query)return a.test(u);throw new Error("Invalid return type for '"+r+"'. Must return a Boolean or Mingo.Query")}}}}(t[r],t)});break;case B:p.each(p.keys(t),function(r){i[r]=function(r,n){return function(t,e,i){var u=o(t,i);return r.call(n,i,u,e)}}(t[r],t)});break;default:p.each(p.keys(t),function(r){i[r]=function(r,n){return function(){var t=Array.prototype.slice.call(arguments);return r.apply(n,t)}}(t[r],t)})}p.extend(F[r],i)},y.CollectionMixin={query:function(r,n){return y.find(this.toJSON(),r,n)},aggregate:function(r){var n=[this.toJSON(),r];return y.aggregate.apply(null,n)}};var _={$group:function(r,n){var t=n[d.key],e=c(r,function(r){return l(r,t,t)}),i=[];return n=p.omit(n,d.key),p.each(e.keys,function(r,t){var u={};p.isUndefined(r)||(u[d.key]=r);for(var o in n)p.has(n,o)&&(u[o]=f(e.groups[t],o,n[o]));i.push(u)}),i},$match:function(r,n){return new y.Query(n).find(r).all()},$project:function(r,n){if(p.isEmpty(n))return r;var t=[],e=p.keys(n),i=!1;if(p.contains(e,d.key)){var o=n[d.key];0!==o&&o!==!1||(e=p.without(e,d.key),p.isEmpty(e)&&(i=!0))}else e.push(d.key);for(var s=0;s<r.length;s++){var c=r[s],f={},h=!1,y=!1,g=[];i&&g.push(d.key),p.each(e,function(r){var t,e=n[r];if(r!==d.key&&0===e&&(y=!0),r===d.key&&p.isEmpty(e))t=c[r];else if(p.isString(e))t=l(c,e,r);else if(1===e||e===!0)t=u(c,r);else if(p.isObject(e)){var i=p.keys(e);if(i=i.length>1?!1:i[0],i!==!1&&p.contains(a(B),i)){var o=x[i](c,e[i],r);p.isUndefined(o)||(t=o),"$slice"==i&&(h=!0)}else t=l(c,e,r)}else g.push(r);p.isUndefined(t)||(f[r]=t)}),(h||y||i)&&(f=p.defaults(f,p.omit(c,g))),t.push(f)}return t},$limit:function(r,n){return p.first(r,n)},$skip:function(r,n){return p.rest(r,n)},$unwind:function(r,n){for(var t=[],e=n.substr(1),i=0;i<r.length;i++){var o=r[i],s=u(o,e);if(!p.isArray(s))throw new Error("Target field '"+e+"' is not of type Array.");p.each(s,function(r){var n=p.clone(o);n[e]=r,t.push(n)})}return t},$sort:function(r,n){if(!p.isEmpty(n)&&p.isObject(n)){var t=p.keys(n);t.reverse().forEach(function(t){var e=[],i=p.groupBy(r,function(r){var n=o(r,t);return e.push(n),n});e=p.sortBy(p.uniq(e),function(r){return r}),-1===n[t]&&e.reverse(),r=[],p.each(e,function(n){Array.prototype.push.apply(r,i[n])})})}return r}},E={},k={$and:function(r,n){if(!p.isArray(n))throw new Error("Invalid expression for $and criteria");var t=[];return p.each(n,function(r){t.push(new y.Query(r))}),{test:function(r){for(var n=0;n<t.length;n++)if(!t[n].test(r))return!1;return!0}}},$or:function(r,n){if(!p.isArray(n))throw new Error("Invalid expression for $or criteria");var t=[];return p.each(n,function(r){t.push(new y.Query(r))}),{test:function(r){for(var n=0;n<t.length;n++)if(t[n].test(r))return!0;return!1}}},$nor:function(r,n){if(!p.isArray(n))throw new Error("Invalid expression for $nor criteria");var t=this.$or("$or",n);return{test:function(r){return!t.test(r)}}},$not:function(r,n){var t={};t[r]=i(n);var e=new y.Query(t);return{test:function(r){return!e.test(r)}}},$where:function(r,n){return p.isFunction(n)||(n=new Function("return "+n+";")),{test:function(r){return n.call(r)===!0}}}};p.extend(E,k);var A={$eq:function(r,t){return r=p.flatten([r]),r=p.find(r,function(r){return p.isEqual(r,t)}),r!==n},$ne:function(r,n){return!this.$eq(r,n)},$in:function(r,n){return r=p.isArray(r)?r:[r],p.intersection(r,n).length>0},$nin:function(r,n){return p.isUndefined(r)||!this.$in(r,n)},$lt:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return t>r}),r!==n},$lte:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return t>=r}),r!==n},$gt:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return r>t}),r!==n},$gte:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return r>=t}),r!==n},$mod:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return p.isNumber(r)&&p.isArray(t)&&2===t.length&&r%t[0]===t[1]}),r!==n},$regex:function(r,t){return r=p.isArray(r)?r:[r],r=p.find(r,function(r){return p.isString(r)&&p.isRegExp(t)&&!!r.match(t)}),r!==n},$exists:function(r,n){return n===!1&&p.isUndefined(r)||n===!0&&!p.isUndefined(r)},$all:function(r,n){var t=this,e=!1;if(p.isArray(r)&&p.isArray(n))for(var i=0;i<n.length;i++){if(!p.isObject(n[i])||!p.contains(p.keys(n[i]),"$elemMatch"))return p.intersection(n,r).length===n.length;e=e||t.$elemMatch(r,n[i].$elemMatch)}return e},$size:function(r,n){return p.isArray(r)&&p.isNumber(n)&&r.length===n},$elemMatch:function(r,n){if(p.isArray(r)&&!p.isEmpty(r))for(var t=new y.Query(n),e=0;e<r.length;e++)if(t.test(r[e]))return!0;return!1},$type:function(r,n){switch(n){case 1:return p.isNumeric(r)&&-1!==(r+"").indexOf(".");case 2:case 5:return p.isString(r);case 3:return p.isObject(r);case 4:return p.isArray(r);case 8:return p.isBoolean(r);case 9:return p.isDate(r);case 10:return p.isNull(r);case 11:return p.isRegExp(r);case 16:return p.isNumeric(r)&&2147483647>=r&&-1===(r+"").indexOf(".");case 18:return p.isNumeric(r)&&r>2147483647&&0x8000000000000000>=r&&-1===(r+"").indexOf(".");default:return!1}}};p.each(p.keys(A),function(r){E[r]=function(r,n){return function(t,e){return{test:function(i){var u=o(i,t);return r.call(n,u,e)}}}}(A[r],A)});var x={$:function(r,n,t){throw new Error("$ not implemented")},$elemMatch:function(r,t,e){var i=o(r,e),u=new y.Query(t);if(p.isUndefined(i)||!p.isArray(i))return n;for(var s=0;s<i.length;s++)if(u.test(i[s]))return[i[s]];return n},$slice:function(r,n,t){var e=o(r,t);if(!p.isArray(e))return e;if(p.isArray(n)){var i=n[0]<0?e.length+n[0]:n,u=i+n[1];n=[i,u]}else{if(!p.isNumber(n))throw new Error("Invalid type for $slice operator");n=0>n?[n]:[0,n]}return Array.prototype.slice.apply(e,n)}},O={$addToSet:function(r,n){var t=p.map(r,function(r){return l(r,n,null)});return p.uniq(t)},$sum:function(r,n){return p.isArray(r)?p.isNumber(n)?r.length*n:p.reduce(r,function(r,t){var e=l(t,n,null);return p.isNumber(e)?r+e:r},0):0},$max:function(r,n){var t=p.max(r,function(r){return l(r,n,null)});return l(t,n,null)},$min:function(r,n){var t=p.min(r,function(r){return l(r,n,null)});return l(t,n,null)},$avg:function(r,n){return this.$sum(r,n)/(r.length||1)},$push:function(r,n){return p.map(r,function(r){return l(r,n,null)})},$first:function(r,t){return r.length>0?l(r[0],t):n},$last:function(r,t){return r.length>0?l(r[r.length-1],t):n}},b={$add:function(r,n){var t=l(r,n,null);return p.reduce(t,function(r,n){return r+n},0)},$subtract:function(r,n){var t=l(r,n,null);return t[0]-t[1]},$divide:function(r,n){var t=l(r,n,null);return t[0]/t[1]},$multiply:function(r,n){var t=l(r,n,null);return p.reduce(t,function(r,n){return r*n},1)},$mod:function(r,n){var t=l(r,n,null);return t[0]%t[1]}},j={$concat:function(r,t){var e=l(r,t,null);return p.contains(e,null)||p.contains(e,n)?null:e.join("")},$strcasecmp:function(r,n){var t=l(r,n,null);return t[0]=p.isEmpty(t[0])?"":t[0].toUpperCase(),t[1]=p.isEmpty(t[1])?"":t[1].toUpperCase(),t[0]>t[1]?1:t[0]<t[1]?-1:0},$substr:function(r,n){var t=l(r,n,null);return p.isString(t[0])?t[1]<0?"":t[2]<0?t[0].substr(t[1]):t[0].substr(t[1],t[2]):""},$toLower:function(r,n){var t=l(r,n,null);return p.isEmpty(t)?"":t.toLowerCase()},$toUpper:function(r,n){var t=l(r,n,null);return p.isEmpty(t)?"":t.toUpperCase()}},q={$dayOfYear:function(r,t){var e=l(r,t,null);if(p.isDate(e)){var i=new Date(e.getFullYear(),0,0),u=e-i,o=864e5;return Math.round(u/o)}return n},$dayOfMonth:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getDate():n},$dayOfWeek:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getDay()+1:n},$year:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getFullYear():n},$month:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getMonth()+1:n},$week:function(r,n){var t=l(r,n,null);t=new Date(+t),t.setHours(0,0,0),t.setDate(t.getDate()+4-(t.getDay()||7));var e=new Date(t.getFullYear(),0,1);return Math.floor(((t-e)/864e5+1)/7)},$hour:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getHours():n},$minute:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getMinutes():n},$second:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getSeconds():n},$millisecond:function(r,t){var e=l(r,t,null);return p.isDate(e)?e.getMilliseconds():n},$dateToString:function(r,n){for(var t=n.format,e=l(r,n.date,null),i=t.match(/(%%|%Y|%m|%d|%H|%M|%S|%L|%j|%w|%U)/g),u=0,o=i.length;o>u;u++){var a=J[i[u]],c=a;if(p.isArray(a)){var f=this[a[0]],h=a[1];c=s(f.call(this,r,e),h)}t=t.replace(i[u],c)}return t}},S={$setEquals:function(r,n){var t=l(r,n,null),e=p.uniq(t[0]),i=p.uniq(t[1]);return e.length!==i.length?!1:0==p.difference(e,i).length},$setIntersection:function(r,n){var t=l(r,n,null);return p.intersection(t[0],t[1])},$setDifference:function(r,n){var t=l(r,n,null);return p.difference(t[0],t[1])},$setUnion:function(r,n){var t=l(r,n,null);return p.union(t[0],t[1])},$setIsSubset:function(r,n){var t=l(r,n,null);return p.intersection(t[0],t[1]).length===t[0].length},$anyElementTrue:function(r,n){for(var t=l(r,n,null)[0],e=0;e<t.length;e++)if(t[e])return!0;return!1},$allElementsTrue:function(r,n){for(var t=l(r,n,null)[0],e=0;e<t.length;e++)if(!t[e])return!1;return!0}},M={$cond:function(r,n){var t,e,i;if(p.isArray(n)){if(3!=n.length)throw new Error("Invalid arguments for $cond operator");t=n[0],e=n[1],i=n[2]}else p.isObject(n)&&(t=n["if"],e=n.then,i=n["else"]);var u=l(r,t,null);return u?l(r,e,null):l(r,i,null)},$ifNull:function(r,t){if(!p.isArray(t)||2!=t.length)throw new Error("Invalid arguments for $ifNull operator");var e=l(r,t,null);return null===e[0]||e[0]===n?e[1]:e[0]}},N={$cmp:function(r,n){var t=l(r,n,null);return t[0]>t[1]?1:t[0]<t[1]?-1:0}};p.each(["$eq","$ne","$gt","$gte","$lt","$lte"],function(r){N[r]=function(n,t){var e=l(n,t,null);return A[r](e[0],e[1])}});var I={$size:function(r,t){var e=l(r,t,null);return p.isArray(e)?e.length:n}},D={$literal:function(r,n){return n}},U={$map:function(r,n){var t=l(r,n.input,null);if(!p.isArray(t))throw new Error("Input expression for $map must resolve to an array");var e=n.as,i=n["in"],u="$"+e,o=r[u];return p.map(t,function(n){r[u]=n;var t=l(r,i,null);return p.isUndefined(o)?delete r[u]:r[u]=o,t})},$let:function(r,n){var t=n.vars,e=n["in"],i={},u=p.keys(t);p.each(u,function(n){var e=l(r,t[n],null),u="$"+n;i[u]=r[u],r[u]=e});var o=l(r,e,null);return p.each(u,function(n){var t="$"+n;p.isUndefined(i[t])?delete r[t]:r[t]=i[t]}),o}},Q={$and:function(r,n){var t=l(r,n,null);return p.every(t)},$or:function(r,n){var t=l(r,n,null);return p.some(t)},$not:function(r,n){return!l(r,n[0],null)}},C=p.extend({},I,b,Q,N,M,q,D,S,j,U),R=y.OP_QUERY="query",P=y.OP_GROUP="group",T=y.OP_AGGREGATE="aggregate",Y=y.OP_PIPELINE="pipeline",B=y.OP_PROJECTION="projection",F={aggregate:C,group:O,pipeline:_,projection:x,query:E},J={"%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],"%%":"%"}}(this); | ||
//# sourceMappingURL=mingo.min.map |
{ | ||
"name": "mingo", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "JavaScript implementation of MongoDB query language", | ||
@@ -23,11 +23,11 @@ "main": "mingo.js", | ||
"underscore": ">=1.8.2", | ||
"backbone": ">=1.1.2", | ||
"tape": ">=2.14.0", | ||
"backbone": ">=1.3.0", | ||
"tape": ">=4.5.1", | ||
"JSON": ">=1.0.0", | ||
"uglify-js": "2.4.x", | ||
"gulp": ">=3.8.11", | ||
"gulp-cli": ">=0.2.0", | ||
"gulp-uglify": ">=1.1.0", | ||
"gulp-rename": ">=1.2.0", | ||
"gulp-plumber": ">=1.0.0" | ||
"uglify-js": "2.6.2", | ||
"gulp": ">=3.9.x", | ||
"gulp-cli": ">=1.2.x", | ||
"gulp-uglify": ">=1.5.x", | ||
"gulp-rename": ">=1.2.x", | ||
"gulp-plumber": ">=1.1.x" | ||
}, | ||
@@ -34,0 +34,0 @@ "keywords": [ |
# Mingo | ||
JavaScript implementation of MongoDB query language | ||
Mingo harnesses the power of MongoDB-style queries and allows direct querying of in-memory | ||
Mingo harnesses the power of MongoDB-style queries and allows direct querying of in-memory | ||
javascript objects in both client and server-side environments. | ||
@@ -46,2 +46,3 @@ | ||
- BackboneJS Integration | ||
- Match against user-defined types | ||
- JSON stream filtering and projection. *NodeJS only* | ||
@@ -170,2 +171,2 @@ | ||
## License | ||
MIT | ||
MIT |
85918
2062
171