我有一个名为“timestamp”的集合,每个time_in,time_out,break_start和break_end都有单独的记录。
我想要的是合并同一日期的记录。 由此: 未合并数据:
{
"_id" : ObjectId("5a94f3e461613268eaecc59c"),
"staff_id" : NumberInt(173),
"time_in" : ISODate("2018-02-27T00:40:00.000+0000"),
"time_out" : null,
"break_start" : null,
"break_end" : null,
"break_type" : null,
"train_delay" : true,
"createdAt" : ISODate("2018-02-27T00:40:00.000+0000"),
"updatedAt" : ISODate("2018-02-27T00:40:00.000+0000"),
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a94f411e5e2d568f1dae527"),
"staff_id" : NumberInt(173),
"time_in" : null,
"time_out" : null,
"break_start" : ISODate("2018-02-27T04:00:00.000+0000"),
"break_end" : null,
"break_type" : "60m",
"train_delay" : false,
"createdAt" : ISODate("2018-02-27T04:00:00.000+0000"),
"updatedAt" : ISODate("2018-02-27T04:00:00.000+0000"),
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a94f41ae5e2d568f1dae528"),
"staff_id" : NumberInt(173),
"time_in" : null,
"time_out" : null,
"break_start" : null,
"break_end" : ISODate("2018-02-27T04:59:00.000+0000"),
"break_type" : null,
"train_delay" : false,
"createdAt" : ISODate("2018-02-27T04:59:00.000+0000"),
"updatedAt" : ISODate("2018-02-27T04:59:00.000+0000"),
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a94f421e5e2d568f1dae529"),
"staff_id" : NumberInt(173),
"time_in" : null,
"time_out" : ISODate("2018-02-27T10:05:00.000+0000"),
"break_start" : null,
"break_end" : null,
"break_type" : null,
"train_delay" : false,
"createdAt" : ISODate("2018-02-27T10:05:00.000+0000"),
"updatedAt" : ISODate("2018-02-27T10:05:00.000+0000"),
"__v" : NumberInt(0)
}
这是以下形象: Not yet merge records.
进入: 合并数据:
{
"_id" : ObjectId("5a94f3e461613268eaecc59c"),
"staff_id" : NumberInt(173),
"time_in" : {
"_id" : ObjectId("5a94f3e461613268eaecc59c"),
"staff_id" : NumberInt(173),
"time_in" : ISODate("2018-02-27T00:40:00.000+0000"),
"time_out" : ISODate("2018-02-27T10:05:00.000+0000"),
"break_start" : ISODate("2018-02-27T04:00:00.000+0000"),
"break_end" : ISODate("2018-02-27T04:59:00.000+0000"),
"break_type" : null,
"train_delay" : true,
"createdAt" : ISODate("2018-02-27T00:40:00.000+0000"),
"updatedAt" : ISODate("2018-02-27T00:40:00.000+0000"),
"__v" : NumberInt(0)
}
这是以下形象: Merged records