在spring-data-mongodb的Criteria運算符中,兩個日期之間的差是否大於0?我寫下面的查詢:Datediff in Criteria operator in spring-data-mongodb does not working
Criteria c= Criteria.where("myDate").gte(startDate).
andOperator(Criteria.where("myDate").lte(endDate).andOperator(Criteria.where("studentId").is(studentId).andOperator(Criteria.where("currDate - myDate").gt(0))));
此查詢不起作用。 如果可能,請幫助我使用spring-data-mongodb獲取此查詢。
編輯: MongoDB的管道查詢如下:
{ "aggregate" : "__collection__" , "pipeline" : [ { "$match" : { "myDate" : { "$gte" : { "$date" : "2000-01-01T07:57:33.231Z"}} , "$and" : [ { "myDate" : { "$lte" : { "$date" : "2015-11-05T07:57:33.231Z"}} , "$and" : [ { "studentId" : "100" , "$and" : [ { "currDate - myDate" : { "$gt" : 0}}]}]}]}} , { "$project" : { "status" : 1}} , { "$group" : { "_id" : { "status" : "$status"} , "activeCount" : { "$sum" : 1}}}]}
問候
克里斯
您能向我們展示您試圖實現的完整邏輯mongodb查詢嗎? – chridam
添加了mongodb查詢 – chiku