我想备份特定日期的特定集合。
我的用例是: 我必须备份90天以上的数据,然后将其从集合中删除。
答案 0 :(得分:0)
一个解决方案是从今天起第90天。并使用mongodump
将其应用于--query=<json>
,该接受json文档作为查询参数。
const today = new Date();
const todayMillis = today.getTime();
/*90th past day from today*/
const nthDayfromToday = todayMillis - (90 * 24 * 60 * 60 * 1000);
console.info(nthDayfromToday); //Lets say this is 1586450232676
使用内容创建文件query.json
-使用上面计算的时间戳:
{ "createdAt": { "$lt": { "$date": 1586450232676 } } }
运行mongodump
命令:
mongodump --db <dbname> --collection <collection> --queryFile query.json