1 | const moment = require('moment');
|
2 | const mongoose = require('mongoose');
|
3 | const domain = require('../');
|
4 |
|
5 | async function main() {
|
6 | await mongoose.connect(process.env.MONGOLAB_URI);
|
7 |
|
8 | const now = new Date();
|
9 | const startThrough = moment(now)
|
10 | .add(-12, 'months')
|
11 | .toDate();
|
12 |
|
13 | console.log('deleting...startThrough:', startThrough);
|
14 |
|
15 | const taskRepo = new domain.repository.Task(mongoose.connection);
|
16 |
|
17 | let result;
|
18 |
|
19 | result = await taskRepo.taskModel.deleteMany({
|
20 | runsAt: { $lt: startThrough }
|
21 | })
|
22 | .exec();
|
23 | console.log('tasks deleted', result);
|
24 |
|
25 |
|
26 | }
|
27 |
|
28 | main().then(() => {
|
29 | console.log('success!');
|
30 | }).catch((error) => {
|
31 | console.error(error);
|
32 | process.exit(1);
|
33 | });
|