mongodb 報錯記錄

紫蕈發表於2024-03-12

1. [Error] Invalid $project :: caused by :: Cannot do inclusion on field data_time in exclusion projection at line 1, column 1

如上,$project中的relation_id:0欄位值更改成1就好了,原因可能在於該欄位正在使用,所以不能置成0,如下,改成1就能執行成功

db.collection_2023.aggregate(
    {$set:{_id:'2023'}},
    {$unionWith:{coll:'collection_2022',pipeline:[ { $set: { _id: "2022" } } ]}},
    {$unionWith:{coll:'collection_2024',pipeline:[ { $set: { _id: "2024" } } ]}},
    {$match:{relation_id:{$in:['P00001']},identity_type:0,data_time:{$gte:'2022-10-01',$lte:'2024-03-07'}}},
    {$project:{relation_id:1,data_time:1,isoWeek:{$isoWeek:{date: {"$dateFromString": {"dateString": "$data_time"}}, "timezone": "Asia/Shanghai"}},
    isoDayOfWeek:{$isoDayOfWeek:{date: {"$dateFromString": {"dateString": "$data_time"}}, "timezone": "Asia/Shanghai"}},
    dayOfWeek:{$dayOfWeek:{date: {"$dateFromString": {"dateString": "$data_time"}}, "timezone": "Asia/Shanghai"}},
    innum:1}}
)

相關文章