Fix $type:4 queries and sorts with numeric indices

Add lots of sort tests.  All new tests in this commit have been verified
against MongoDB (2.5).