Be sure to avoid "$where" queries unless absolutely necessary, as they are much slower than regular queries. Each document is converted from BSON to a JavaScript object and then run through the "$where" expression. Also, indexes cannot be used. So consider the usage of "$where" when you are desperate.
Use regular queries as prefilters, combined with "$where" without sacrificing performance. If possible, use an index to filter based on non-"$where" clauses, "$where" is only used to tune the results.