mongodb 报错记录

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}}
)

 

posted @ 2024-03-12 11:29  紫蕈  阅读(87)  评论(0编辑  收藏  举报