$minute(聚合)
定义
行为
例子 | 结果 | ||||
---|---|---|---|---|---|
| 1 | ||||
| 0 | ||||
| 31 | ||||
| 10 | ||||
| error | ||||
| error | ||||
| error |
注意
$minute 不支持将字符串用作参数。
例子
使用以下文档创建 sales
集合:
db.sales.insertOne( { "_id" : 1, "item" : "abc", "price" : 10, "quantity" : 2, "date" : ISODate("2014-01-01T08:15:39.736Z") } )
以下聚合使用 $minute
和其他日期表达式来拆分 date
字段:
db.sales.aggregate( [ { $project: { year: { $year: "$date" }, month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, hour: { $hour: "$date" }, minutes: { $minute: "$date" }, seconds: { $second: "$date" }, milliseconds: { $millisecond: "$date" }, dayOfYear: { $dayOfYear: "$date" }, dayOfWeek: { $dayOfWeek: "$date" }, week: { $week: "$date" } } } ] )
操作返回以下结果:
{ "_id" : 1, "year" : 2014, "month" : 1, "day" : 1, "hour" : 8, "minutes" : 15, "seconds" : 39, "milliseconds" : 736, "dayOfYear" : 1, "dayOfWeek" : 4, "week" : 0 }