我嘗試在 mongodb 中按月查詢查找,我在 Daq 集合中的數據是這樣的:" _id" : ObjectId("5f14081c14c08a261b816d57"), "battery_voltage" : 3673, "total_usage" : 0.483, "signal" : 14, "samplehour" : "2020-07-18T23:59:59-04:00", "sampledate" : "2020-07-18T23:59:59-04:00",這是我的查詢:let n = moment().month()let test = await Daq.aggregate([ {$addFields: { "month" : {$month: '$sampledate'}}}, {$match: { month: n}}]);我也已經嘗試過了:let n = moment().month()let test = await Daq.aggregate([ {$project: { "month" : {$month: '$sampledate'}}}, {$match: { month: n}}]);但結果總是"message": "can't convert from BSON type string to Date"你們如何解決這個問題?
按當月過濾 mongodb 數據
蝴蝶不菲
2022-11-27 16:44:09