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

后端 未结 8 421
悲哀的现实
悲哀的现实 2021-01-30 10:45

I\'m trying to use the mongodump command to dump out a bunch of records created on a specific date. The records include a \"ts\" field which is a MongoDB Date() object.

8条回答
  •  心在旅途
    2021-01-30 11:08

    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
    

提交回复
热议问题