@chevre/domain
Version:
Chevre Domain Library for Node.js
41 lines (33 loc) • 1.37 kB
text/typescript
// tslint:disable:no-console
import * as moment from 'moment-timezone';
import * as mongoose from 'mongoose';
import { chevre } from '../../../../lib/index';
const EXCLUDED_PROJECT_ID = String(process.env.EXCLUDED_PROJECT_ID);
async function main() {
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
const aggregateDate = new Date('2024-11-03T10:00:00+09:00');
const aggregateDurationUnit = 'days';
// const aggregateDurationUnit = 'hours';
const startFrom: Date = moment(aggregateDate)
.utc()
.startOf(aggregateDurationUnit)
.toDate();
const startThrough: Date = moment(aggregateDate)
.utc()
.endOf(aggregateDurationUnit)
.toDate();
const startTime = process.hrtime();
const aggregateResult = await orderRepo.aggregateOrder({
project: { id: { $ne: EXCLUDED_PROJECT_ID } },
orderDate: { $gte: startFrom, $lte: startThrough }
});
console.log('aggregateOrder:result', aggregateResult, startFrom, startThrough);
const diff = process.hrtime(startTime);
console.log(`importing chevre took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
}
main()
.then(() => {
console.log('success!');
})
.catch(console.error);