|
|
@@ -192,16 +192,16 @@ proto._parseAll = function _parseAll(name, element){
|
|
|
// $all : [ { $elemMatch : ... }, 5 ]
|
|
|
return {code:ErrorCodes.BAD_VALUE, description:"$all/$elemMatch has to be consistent"};
|
|
|
}
|
|
|
-
|
|
|
- if ("$elemMatch" != hopefullyElemMatchElement.keys()[0]) {
|
|
|
+
|
|
|
+ if ("$elemMatch" != Object.keys(hopefullyElemMatchElement)[0]) {
|
|
|
// $all : [ { $elemMatch : ... }, { x : 5 } ]
|
|
|
return {code:ErrorCodes.BAD_VALUE, description:"$all/$elemMatch has to be consistent"};
|
|
|
}
|
|
|
|
|
|
- status = this._parseElemMatch("", hopefullyElemMatchElement[hopefullyElemMatchElement.keys()[0]]); // TODO: wrong way to do this?
|
|
|
+ status = this._parseElemMatch("", hopefullyElemMatchElement['$elemMatch'] ); // TODO: wrong way to do this?
|
|
|
if (status.code != ErrorCodes.OK)
|
|
|
return status;
|
|
|
- temp.add(new ArrayMatchingMatchExpression(status.result));
|
|
|
+ temp.add(status.result);
|
|
|
}
|
|
|
|
|
|
return {code:ErrorCodes.OK, result:temp};
|
|
|
@@ -346,20 +346,26 @@ proto._parseElemMatch = function _parseElemMatch(name, element){
|
|
|
*/
|
|
|
proto._parseMOD = function _parseMOD(name, element){
|
|
|
// File: expression_parser.cpp lines: 360-387
|
|
|
-
|
|
|
+ var d,r;
|
|
|
if (!(element instanceof Array))
|
|
|
return {code:ErrorCodes.BAD_VALUE, result:"malformed mod, needs to be an array"};
|
|
|
if (element.length < 2)
|
|
|
return {code:ErrorCodes.BAD_VALUE, result:"malformed mod, not enough elements"};
|
|
|
if (element.length > 2)
|
|
|
return {code:ErrorCodes.BAD_VALUE, result:"malformed mod, too many elements"};
|
|
|
- if (!(element[0] instanceof Number))
|
|
|
+ if (!(element[0] instanceof Number || typeof(element[0]) == 'number')) {
|
|
|
return {code:ErrorCodes.BAD_VALUE, result:"malformed mod, divisor not a number"};
|
|
|
- if (!(element[1] instanceof Number))
|
|
|
- return {code:ErrorCodes.BAD_VALUE, result:"malformed mod, remainder not a number"};
|
|
|
+ } else {
|
|
|
+ d = element[0];
|
|
|
+ }
|
|
|
+ if (!(element[1] instanceof Number || typeof(element[1]) == 'number')) {
|
|
|
+ r = 0;
|
|
|
+ } else {
|
|
|
+ r = element[1];
|
|
|
+ }
|
|
|
|
|
|
var temp = new ModMatchExpression();
|
|
|
- var status = temp.init( name, element[0], element[1]);
|
|
|
+ var status = temp.init( name, d, r);
|
|
|
if (status.code != ErrorCodes.OK)
|
|
|
return status;
|
|
|
|
|
|
@@ -422,40 +428,36 @@ proto._parseNot = function _parseNot(name, element){
|
|
|
*/
|
|
|
proto._parseRegexDocument = function _parseRegexDocument(name, doc){
|
|
|
// File: expression_parser.cpp lines: 402-442
|
|
|
- var regex, regexOptions, e;
|
|
|
-
|
|
|
- for (var i = 0; i < doc.length; i++) {
|
|
|
- e = doc[i];
|
|
|
- switch (e.getGtLtOp()) {
|
|
|
- case 'opREGEX':
|
|
|
- if (e instanceof String) {
|
|
|
- regex = e;
|
|
|
- }
|
|
|
- else if (e instanceof RegExp) {
|
|
|
- var str = e.toString(),
|
|
|
- flagIndex = 0;
|
|
|
- for (var c = str.length; c > 0; c--){
|
|
|
- if (str[c] == '/') {
|
|
|
- flagIndex = c;
|
|
|
- break;
|
|
|
- }
|
|
|
+ var regex = '', regexOptions = '', e;
|
|
|
+ debugger;
|
|
|
+ if(doc['$regex']) {
|
|
|
+ if(doc['$regex'] instanceof RegExp) {
|
|
|
+ e = doc['$regex'];
|
|
|
+ var str = e.toString(),
|
|
|
+ flagIndex = 0;
|
|
|
+ for (var c = str.length; c > 0; c--){
|
|
|
+ if (str[c] == '/') {
|
|
|
+ flagIndex = c;
|
|
|
+ break;
|
|
|
}
|
|
|
- regex = str.substr(1, flagIndex-1);
|
|
|
- regexOptions = str.substr(flagIndex, str.length);
|
|
|
- }
|
|
|
- else {
|
|
|
- return {code:ErrorCodes.BAD_VALUE, description:"$regex has to be a string"};
|
|
|
}
|
|
|
+ regex = (flagIndex? str : str.substr(1, flagIndex-1));
|
|
|
+ regexOptions = str.substr(flagIndex, str.length);
|
|
|
+ } else if (e instanceof String) {
|
|
|
+ regex = e;
|
|
|
+ } else {
|
|
|
+ return {code:ErrorCodes.BAD_VALUE, description:"$regex has to be a string"};
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- break;
|
|
|
- case 'opOPTIONS':
|
|
|
- if (!(e instanceof String))
|
|
|
- return {code:ErrorCodes.BAD_VALUE, description:"$options has to be a string"};
|
|
|
+ if(doc['$options']) {
|
|
|
+ e = doc['$options'];
|
|
|
+ if(typeof(e) == 'string') {
|
|
|
regexOptions = e;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ } else {
|
|
|
+ return {code:ErrorCodes.BAD_VALUE, description:"$options has to be a string"};
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
var temp = new RegexMatchExpression();
|