Can just add in that I just did a test myself, 2 million documents in
a collection (randomly generated and distributed), doing a partially
indexed query (14000 results) and going through all the results takes
about 600ms, doing an $in query on those 14000 ids takes 300ms. Since
the initial query isn't entirely indexed this isn't really a fair
comparison, but from what I can gather I have no such problems with
MongoDB 1.6.4 and PHP-driver 1.1.0.
However, something I did notice was that when making the first query
entirely indexed (120 000 results), it took about 1700ms to do the
indexed query, while doing the $in query took about 7000ms... which is
bad... however, I do believe there is a really simple reason for that,
which probably should be fixed... while doing the $in query, the
mongod-console outputs the entire query (meaning, approx ~50 000 lines
of objectids), which is SLOW. And I can't find a way to prevent it
from doing that (--quiet doesn't do it). Trimming down query output
longer than a few lines is probably a good idea.
Also, just adding in that while trying to CTRL-C out of the $in query,
the query continued outputting the query string, but PHP immediately
sent the following PHP-error.
"Fatal error: Uncaught exception 'MongoCursorException' with message
'bad response length: 19, max: 67108864, did the db assert?' in
XXX.php:YYY Stack trace: #0 XXX.php(YYY): MongoCursor->next() #1
{main} thrown in XXX.php on line YYY"
It may even be by design, but now you know, just in-case.