|
@@ -22,6 +22,13 @@ var MatchDocumentSource = module.exports = function MatchDocumentSource(query, c
|
|
|
base.call(this, ctx);
|
|
base.call(this, ctx);
|
|
|
this.query = query; // save the query, so we can check it for deps later. THIS IS A DEVIATION FROM THE MONGO IMPLEMENTATION
|
|
this.query = query; // save the query, so we can check it for deps later. THIS IS A DEVIATION FROM THE MONGO IMPLEMENTATION
|
|
|
this.matcher = new matcher(query);
|
|
this.matcher = new matcher(query);
|
|
|
|
|
+
|
|
|
|
|
+ // not supporting currently $text operator
|
|
|
|
|
+ // set _isTextQuery to false.
|
|
|
|
|
+ // TODO: update after we implement $text.
|
|
|
|
|
+ if (klass.isTextQuery(query)) throw new Error("$text pipeline operation not supported");
|
|
|
|
|
+ this._isTextQuery = false;
|
|
|
|
|
+
|
|
|
}, klass = MatchDocumentSource, base = require('./DocumentSource'), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
}, klass = MatchDocumentSource, base = require('./DocumentSource'), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
|
|
klass.matchName = "$match";
|
|
klass.matchName = "$match";
|
|
@@ -33,6 +40,10 @@ proto.getSourceName = function getSourceName(){
|
|
|
proto.getNext = function getNext(callback) {
|
|
proto.getNext = function getNext(callback) {
|
|
|
if (!callback) throw new Error(this.getSourceName() + ' #getNext() requires callback');
|
|
if (!callback) throw new Error(this.getSourceName() + ' #getNext() requires callback');
|
|
|
|
|
|
|
|
|
|
+ if (this.expCtx.checkForInterrupt && this.expCtx.checkForInterrupt() === false) {
|
|
|
|
|
+ return callback(new Error('Interrupted'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
var self = this,
|
|
var self = this,
|
|
|
next,
|
|
next,
|
|
|
test = function test(doc) {
|
|
test = function test(doc) {
|
|
@@ -86,11 +97,11 @@ klass.uassertNoDisallowedClauses = function uassertNoDisallowedClauses(query) {
|
|
|
for(var key in query){
|
|
for(var key in query){
|
|
|
if(query.hasOwnProperty(key)){
|
|
if(query.hasOwnProperty(key)){
|
|
|
// can't use the Matcher API because this would segfault the constructor
|
|
// can't use the Matcher API because this would segfault the constructor
|
|
|
- if (query[key] == "$where") throw new Error("code 16395; $where is not allowed inside of a $match aggregation expression");
|
|
|
|
|
|
|
+ if (key === "$where") throw new Error("code 16395; $where is not allowed inside of a $match aggregation expression");
|
|
|
// geo breaks if it is not the first portion of the pipeline
|
|
// geo breaks if it is not the first portion of the pipeline
|
|
|
- if (query[key] == "$near") throw new Error("code 16424; $near is not allowed inside of a $match aggregation expression");
|
|
|
|
|
- if (query[key] == "$within") throw new Error("code 16425; $within is not allowed inside of a $match aggregation expression");
|
|
|
|
|
- if (query[key] == "$nearSphere") throw new Error("code 16426; $nearSphere is not allowed inside of a $match aggregation expression");
|
|
|
|
|
|
|
+ if (key === "$near") throw new Error("code 16424; $near is not allowed inside of a $match aggregation expression");
|
|
|
|
|
+ if (key === "$within") throw new Error("code 16425; $within is not allowed inside of a $match aggregation expression");
|
|
|
|
|
+ if (key === "$nearSphere") throw new Error("code 16426; $nearSphere is not allowed inside of a $match aggregation expression");
|
|
|
if (query[key] instanceof Object && query[key].constructor === Object) this.uassertNoDisallowedClauses(query[key]);
|
|
if (query[key] instanceof Object && query[key].constructor === Object) this.uassertNoDisallowedClauses(query[key]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -103,6 +114,25 @@ klass.createFromJson = function createFromJson(jsonElement, ctx) {
|
|
|
return matcher;
|
|
return matcher;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+proto.isTextQuery = function isTextQuery() {
|
|
|
|
|
+ return this._isTextQuery;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+klass.isTextQuery = function isTextQuery(query) {
|
|
|
|
|
+ for (var key in query) {
|
|
|
|
|
+ var fieldName = key;
|
|
|
|
|
+ if (fieldName === "$text") return true;
|
|
|
|
|
+ if (query[key] instanceof Object && query[key].constructor === Object && this.isTextQuery(query[key])) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+klass.setSource = function setSource (source) {
|
|
|
|
|
+ this.setSource(source);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
proto.getQuery = function getQuery() {
|
|
proto.getQuery = function getQuery() {
|
|
|
return this.matcher._pattern;
|
|
return this.matcher._pattern;
|
|
|
};
|
|
};
|