Closed
Description
It looks like the query optimizer could be improved to handle short circuited logical And/Or expressions. Currently the optimizer/translator will generate invalid mango queries.
Example:
bool useFilter = true; //from user input...
var mango = _database.Where(doc => useFilter && doc.MyField == "foobar").ToString();
The query generated is
{
"$and" : [
true,
"$eq": {
"myfield":"foobar"
}
]
}
I would have expected the optimizer to 'prune' all the 'true/false' branches for And/Or. Instead, the above query returns nothing.
The workaround is to do this:
if (useFilter) //use constant outside of expression
{
_database.Where(...);
}
It works, but it's not intuitive to the user.