Tips on MongoDB $in query
By default, if you don't use sort, the returned results always ordered by the order they inserted.
It is also true for MySQL.
mysql> select * from category where short_name in ( 'mysql', 'cpp','oracle','stl'); +----+------------+-----------+-----------+----------+------+ | id | short_name | show_name | parent_id | keywords | desc | +----+------------+-----------+-----------+----------+------+ | 11 | oracle | Oracle | 0 | | | | 12 | mysql | MySQL | 0 | | | | 22 | cpp | C++ | 0 | | | | 29 | stl | STL | 22 | | | +----+------------+-----------+-----------+----------+------+ 4 rows in set (0.00 sec) mysql> select * from category where short_name in ( 'mysql', 'cpp','oracle','stl') order by short_name; +----+------------+-----------+-----------+----------+------+ | id | short_name | show_name | parent_id | keywords | desc | +----+------------+-----------+-----------+----------+------+ | 22 | cpp | C++ | 0 | | | | 12 | mysql | MySQL | 0 | | | | 11 | oracle | Oracle | 0 | | | | 29 | stl | STL | 22 | | | +----+------------+-----------+-----------+----------+------+ 4 rows in set (0.00 sec)
In MongoDB, use sort: