我目前正在尝试通过汇总从mongodb集合中排除特定日期。但是,由于某些原因,我无法做到这一点。
这是我的汇总函数:
collection.aggregate([
{$match:{$ne:[moment(value, 'M-DD-YYYY').startOf('day').toDate(), moment(value, 'M-DD-YYYY').endOf('day').toDate() ]}}])
值是日期:“ 7-17-2018”
答案 0 :(得分:0)
您需要在日期范围查询中颠倒install-file
的逻辑,并使用逻辑comparison operators运算符来查询日期范围的补码,即
const momentObj = moment(value, 'M-DD-YYYY');
const start = momentObj.startOf('day').toDate();
const end = momentObj.endOf('day').toDate();
collection.aggregate([
{ '$match': {
'$or': [
{ 'invoiceDate': { '$lt': start } },
{ 'invoiceDate': { '$gt': end } }
]
} }
], (err, data) => console.log(data))