-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #49 - $where operator is not evaluated last #50
Conversation
This change stores off any $where operators encountered in the _compile function, and then calls _processOperator on each after _processOperator is called for other operators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor feedback for simplicity and consistency
mingo.js
Outdated
@@ -1342,6 +1348,11 @@ Mingo.Query.prototype = { | |||
} | |||
} | |||
} | |||
var self = this; | |||
console.log(whereOperators); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug statement
mingo.js
Outdated
if (inArray(['$where'], field)) { | ||
whereOperators.push({field: field, expr: expr}); | ||
} | ||
else if (inArray(['$and', '$or', '$nor'], field)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the style
if (<condition>) {
<statements>
} else if (<codition2>) {
...
mingo.js
Outdated
for (var field in this.__criteria) { | ||
if (has(this.__criteria, field)) { | ||
var expr = this.__criteria[field] | ||
if (inArray(['$and', '$or', '$nor', '$where'], field)) { | ||
// save $where operators to be executed after other operators | ||
if (inArray(['$where'], field)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an equality check will do here. '$where' === field
mingo.js
Outdated
@@ -1327,10 +1327,16 @@ Mingo.Query.prototype = { | |||
|
|||
assert(isObject(this.__criteria), 'Criteria must be of type Object') | |||
|
|||
var whereOperators = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one $where
expression allowed in query so this can be single valued
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with the updates though I must apologize for not spotting earlier that you worked on the wrong file.
Development happens on modularized files in the lib/ folder and the make script builds the mingo.js file. The correct file to edit is https://github.com/kofrasa/mingo/blob/development/lib/query.js.
Then you can run the command make mingo.js to amalgamate and then make test to run the unit tests. This one is on me, but I will appreciate if you made the final update.
Thanks for the good work done so far.
No worries, I should have caught that mingo.js is built from all of the files in lib. |
Thanks for your contribution. |
This change stores off any $where operators encountered in the _compile function, and then calls _processOperator on each after _processOperator is called for other operators.