|
@@ -14,6 +14,7 @@ var MatchDocumentSource = module.exports = (function(){
|
|
|
var klass = module.exports = MatchDocumentSource = function MatchDocumentSource(query /*, pCtx*/){
|
|
|
if(arguments.length !== 1) throw new Error("one arg expected");
|
|
|
base.call(this);
|
|
|
+ this.query = query; // save the query, so we can check it for deps later. THIS IS A DEVIATION FROM THE MONGO IMPLEMENTATION
|
|
|
this.matcher = sift(query);
|
|
|
}, base = require('./FilterBaseDocumentSource'), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
@@ -36,13 +37,40 @@ var MatchDocumentSource = module.exports = (function(){
|
|
|
};
|
|
|
|
|
|
// DEPENDENCIES
|
|
|
- var sift = require("sift");
|
|
|
+ var sift = require("sift"),
|
|
|
+ traverse = require("traverse");
|
|
|
|
|
|
klass.matchName = "$match";
|
|
|
proto.getSourceName = function getSourceName(){
|
|
|
return klass.matchName;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds dependencies to the contained ObjectExpression
|
|
|
+ *
|
|
|
+ * THIS IS A DEVIATION FROM THE MONGO IMPLEMENTATION.
|
|
|
+ *
|
|
|
+ * @param {deps} An object that is treated as a set of strings
|
|
|
+ * @return A string that is part of the GetDepsReturn enum
|
|
|
+ **/
|
|
|
+ proto.getDependencies = function getDependencies(deps) {
|
|
|
+ var tmpArr = [];
|
|
|
+ // We need to construct a facets for both keys and values if they contain dotted paths
|
|
|
+ traverse(this.query).forEach(function(value) {
|
|
|
+ var key = this.key;
|
|
|
+ if (typeof value == "string" && value[0] == "$") { // If we find a document path in the value
|
|
|
+ tmpArr.push(value.replace(/^\$/, ""));
|
|
|
+ } else if (key && /^[A-Za-z_]/.test(key)) { //if we find a non-operator as a key
|
|
|
+ tmpArr.push(key);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ for (var i = 0; i < tmpArr.length; i++) {
|
|
|
+ deps[tmpArr[i]] = 1;
|
|
|
+ }
|
|
|
+ return "SEE_NEXT";
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* Create an object that represents the document source. The object
|
|
|
* will have a single field whose name is the source's name. This
|