Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
484 B
2
Indexable
Never

	async created() {
		try {
			const startOfThisMonth = moment().startOf('month').toDate();
			const pipeline = [
				{
					$match: {
						status: { $ne: 'cancelled' },
						createdAt: { $gte: startOfThisMonth },
					},
				},
				{
					$group: {
						_id: null,
						grand: { $sum: '$grandTotal' },
					},
				},
			];
			const res = await this.adapter.model.aggregate(pipeline);
			console.log(res);
			console.log(res.length);
		} catch (err) {
			console.log(err);
		}
	},