在下面提到的查询中,当我尝试使用project1"完成"和" planFinish" to project2 and conversion" String"约会到#34; IsoDate"它的显示" QUERY [thread1]错误:ISO日期无效"
db.prOrder.aggregate(
[
{$match:{"enterpriseBid":"abc","prodOrderLineItems.planFinishDate":{$exists:true}}
},
//Stage2
{$unwind:{path:"$prodOrderLineItems",preserveNullAndEmptyArrays:false}},
//Stage3
{$project:{prodOrderNumber:1,enterpriseBid:1,
"planFinish":{$dateToString:{format:"%Y-%m-%d",date:"$prodOrderLineItems.planFinishDate"}},
"finish":{$dateToString:{format:"%Y-%m-%d",
date:{$cond:[{"$ne":["$prodOrderLineItems.finishDate",null]},"$prodOrderLineItems.finishDate",new ISODate()]}}}}
},
//Stage5
{$project:{prodOrderNumber:1,"enterpriseBid":1,"orderNumber":1,"finish":1,
"planFinish":1,"dateComp":{"$cmp":[ISODate("$planFinish"), ISODate("$finish")]}}
},
//Stage6
{$match:{"dateComp":-1}
},
{$group:{"_id":{"orderNumber":"$prodOrderNumber","finish":"$finish","planFinish":"$planFinish"}}}
]
).forEach(function(doc){
printjson(doc);
});
答案 0 :(得分:0)
我得到了这个解决方案并且工作正常
//Stage5
{$project:{"orderNumber":1,"lastShipDate":1,"promisedShipDate":1,"dateComp":{"$cmp":[{
type:Date,
default:"$promisedShipDate"},
{type:Date ,default:"$lastShipDate"}
]}}},