{
"_id" : ObjectId("5a4212b49e710765c486d7c6"),
"student_id" : ObjectId("5a3df85bcc6425291c54d2ad"),
"attendance_status" : true,
"create_at" : 1514279592137.0,
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a4212b49e710765c486d7c7"),
"student_id" : ObjectId("5a3df85bcc6425291c54d2ae"),
"attendance_status" : true,
"create_at" : 1514279592137.0,
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a4212b49e710765c486d7c9"),
"student_id" : ObjectId("5a3df85bcc6425291c54d2b0"),
"attendance_status" : true,
"create_at" : 1514279592137.0,
"__v" : NumberInt(0)
}
私は時間をtrampとして保存します。私は作成月に基づいてデータを取得したい。それを達成するために?mongo dbで特定の月までにデータを見つける方法
次のクエリを使用してデータを検索しようとしています。
Attendance.aggregate(
[{
$project: {
create_at: "$create_at",
student_id: "$student_id",
attendance_status: "$attendance_status",
month: {
$month: "$create_at"
}
}
},
{
$match: {
"month": req.body.month
}
},
])
作成月に基づいて出力します。 req.body.month = 3を送ってください。3ヶ月間のデータが必要です。
の詳細については、あなたの質問について、より具体的なことができますか? mongodbを照会するのにあなたはどのライブラリを使用していますか?期待される成果は?例が役に立ちます。 –
[mongodb集約でミリ秒を現在に変換する方法は?](https://stackoverflow.com/questions/29889719/how-to-convert-milliseconds-to-date-in-mongodb-aggregation) – Veeram