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

后端 未结 8 412
悲哀的现实
悲哀的现实 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 10:47

    In MongoDB 3.2, we can use --queryFile option with mongodump.

    first of all, create a json file:

    //query.json
    {"serverTime": {"$gte": ISODate("2016-01-30T16:00:00.000Z"), "$lt": ISODate("2016-01-31T16:00:00.000Z")}}
    

    next,use mongodump:

    mongodump --db  --collection  --queryFile query.json
    

    simple and clear.

提交回复
热议问题