You can use the $where operator as code_monkey_steve says, but be sure you do with mongo version >= 2.4. Before that version no javascript can be run on parallel on the same server. The sleep command is javascript, so it would apparently block other javascript queries you could be making.