0
全収集date
フィールドの最大値を取得したいとします。4programmers
。mongo-java-driverを使用したフィールドの最大値
db.getCollection("4programmers").aggregate([
{
$group:
{
_id: null,
max : {$max: "$date"}
}
}
])
をし、それが日付ISODate("2017-10-20T17:12:37.000+02:00")
で文書を返しますが、私はJavaで書くとき:
のmongoシェルでは、私は書くことができ、結果として
Date d = collection.aggregate(
Arrays.asList(
Aggregates.group("$date", Accumulators.max("maxx", "$date"))
)
).first().getDate("maxx");
System.out.println(d);
私が取得:Fri Oct 20 00:44:50 CEST 2017
first()
に何か問題がありますか?