为什么下面的代码有效
db.getCollection('CustomerData').aggregate([
{$addFields: {
"month": {$month: new Date("2018-09-18T00:00:00.000Z")},
"year": {$year: new Date("2018-09-18T00:00:00.000Z")}
}
},
{$match: { month: 9, year: 2018, flag: 'dealer' } }
])
但不是这个
db.getCollection('CustomerData').aggregate([
{$addFields: {
"month": {$month: new Date("$date")},
"year": {$year: new Date("$date")}
}
},
{$match: { month: 9, year: 2018, flag: 'dealer' } }
])
注意:在文档中有日期字段。我正在使用 MongoClient。样本数据。
{
"_id" : ObjectId("5b9ed3f221f0c70c7c0fd035"),
"customerName" : "aaa",
"date" : "2018-09-18T00:00:00.000Z",
"flag" : "dealer"
}