I need to find out that if it is possible to use function in $where clause string like this:
db.myCollection.find( "this.name == 'xyz' || function() {return 1>0;} || this.name == 'abc'" );
Thanks in advance.
I'm not quite sure what you're trying to do, but put all your checks in a single function that's the value of the $where
:
db.myCollection.find({$where: function() {
return this.name == 'xyz' || 1>0 || this.name == 'abc';
}});
It is possible to use nested functions within functions in JS but there are some considerations as this question will tell you: JavaScript Nested function
However, as @JohnnyHK said, this isn't really a good way of doing a $where
, if there is at all.