0
實際上,我從我的前端發送日期到mongo,然後它將日期減少1,當我回顧時,它會給出正確的日期,但是當我們根據月份和年份從$月,$ year屬性,它會根據日期值進行聚合爲什麼? 如果沒問題,那麼給我解決方案來執行正確的聚合。 彙總代碼是 -在MongoDB中的ISO日期
DBObject projectFields = new BasicDBObject();
projectFields.put("creationDate","$creationDate");
projectFields.put("month",new BasicDBObject("$month", "$creationDate"));
projectFields.put("year",new BasicDBObject("$year", "$creationDate"));
projectFields.put("day",new BasicDBObject("$dayOfMonth", "$creationDate"));
projectFields.put("batchQty","$batchQty");
DBObject projectObj = new BasicDBObject("$project", projectFields);
DBObject groupIdFieldsObj = new BasicDBObject();
groupIdFieldsObj.put("month","$month");
groupIdFieldsObj.put("year","$year");
groupFieldsObj.put("_id", groupIdFieldsObj);
DBObject groupSumFieldsObj = new BasicDBObject();
groupSumFieldsObj.put("$sum", "$batchQty");
groupFieldsObj.put("batchQty", groupSumFieldsObj);
DBObject groupObj = new BasicDBObject("$group", groupFieldsObj);
DBObject outCollObj = new BasicDBObject();
outCollObj.put("$out", "salesExportData");
coll.aggregate(groupObj,projectObj,outCollObj);
在此先感謝。
您可以添加一些示例文檔嗎? – Veeram