How can I use mongodump to dump out records matching a specific date range?

I solved it - the magic incantation I was looking for is:

mongodump --query "{\"ts\":{\"\$gt\":{\"\$date\":`date -d 2011-08-10 +%s`000},\"\$lte\":{\"\$date\":`date -d 2011-08-11 +%s`000}}}"

A more human-readable version than @SimonWillison's escaped version:

--query "{ time: { \$gt: new Date(1312959600000), \$lt: new Date(1313046000000) }}"

(Note the dollarsigns still need to be escaped.)

I got the millisecond timestamps by creating dates in the shell, e.g.:

> var targetDateStart = new Date(2011, 7, 10);
> var targetDateEnd = new Date(2011, 7, 11);
> targetDateStart.getTime();
1312959600000
> targetDateEnd.getTime();
1313046000000