我有这个猫鼬方法/查询,它从某个用户中查找所有“收入”,但前提是“收入”的日期在当月内。
码:
module.exports.getMonthlyIncome = function(userId, callback){
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth();
const date = now.getDate();
const start = new Date(year, month, 1);
const end = new Date(year, month, 30);
Income.find({owner: userId, date: { $gte: start, $lt: end }}, callback);
}
Run Code Online (Sandbox Code Playgroud)
结果:
[
{
"_id": "58cc9ee50fe27e0d2ced5193",
"amount": 600,
"description": "Ripco Salary",
"owner": "58cc9e950fe27e0d2ced5192",
"__v": 0,
"date": "2017-03-17T00:00:00.000Z"
},
{
"_id": "58ccc3cfca6ea10980480d42",
"amount": 450,
"description": "Another Ripped co salary",
"owner": "58cc9e950fe27e0d2ced5192",
"__v": 0,
"date": …Run Code Online (Sandbox Code Playgroud)