离开架构
mongoose.Schema({
_id: String
});
状态架构
mongoose.Schema({
_id: String,
LeaveId: String,
Time: Date
});
状态架构中的 LeaveId 是 _id 对保留架构的引用。您可能已经猜到离开和状态有一对多的关系。
现在,我想找到状态的列表,其中只包含最新状态 离开。
示例
离开收藏
[
{
_id: '<id-1>'
},
{
_id: '<id-2>'
}
]
状态收集
[
{
_id: '<id-3>',
LeaveId: '<id-1>',
Time: 2013-0-0
},
{
_id: '<id-4>',
LeaveId: '<id-1>',
Time: 2014-0-0
},
{
_id: '<id-5>',
LeaveId: '<id-2>',
Time: 2016-0-0
},
{
_id: '<id-6>',
LeaveId: '<id-2>',
Time: 2015-0-0
}
]
预期产出
[
{
_id: '<id-4>',
LeaveId: '<id-1>',
Time: 2014-0-0
},
{
_id: '<id-5>',
LeaveId: '<id-2>',
Time: 2016-0-0
}
]