I need to make query like this in MongoDB:
db.collection.find( { $where : "(this.type & some_num) ^ some_num == 0"} )
Some_num is a variable and it can be any integer.
I read the doc at here which says Javascript query slows down execution and also it cannot use an index and requires a table scan.
What is the alternative to the above query?
The best thing to do in Mongo is to store the calculated value that you plan to search on in a field and then create an index on it. Otherwise, you are pretty much doomed to scanning the whole collection.
$where must be slow.
It would be better something like $bitand, but it is not implemented yet. see https://jira.mongodb.org/browse/SERVER-3518.
Possible solution (for me) was using arrays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With