MongoDB的我已保存的文件格式的數據庫:創建多個MongoDB中的春天數據彙總查詢
{
"achievement": [
{
"userFromId":"max",
"userToId":"peter",
"date":"2016-01-25",
"pointCount":1,
"description":"good work",
"type":"THANKS"
}
]
}
如何獲得的記錄數在數據庫中(如果有的話)的某個日期,在哪些人感謝其他人。 我創建了一個查詢檢索數據:
DBObject clause1 = new BasicDBObject("userFromId", userFromId);
DBObject clause2 = new BasicDBObject("userToId", userToId);
DBObject clause3 = new BasicDBObject("sendDate", localDate);
DBObject clause4 = new BasicDBObject("type", Thanks);
BasicDBList or = new BasicDBList();
or.add(clause1);
or.add(clause2);
or.add(clause3);
or.add(clause4);
DBObject query = new BasicDBObject("$or", or);
但我不知道怎麼去記錄的數量和使用聚合如何重寫查詢? 例如:
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group("userFromId")
.first("userFromId").as("userFromId")
.sum("pointCount").as("pointCount"));
我不知道如何添加幾個參數。 如果到數據庫的數據不存在,返回請求是什麼?
感謝您的幫助
您可以添加預期的輸出?你爲什麼要使用聚合? – Veeram
我需要檢查真或假 我認爲通過清單 然後檢查集合中是否有數據。 – Garazd