db.collection('codelist').aggregate().lookup({
from: 'patroltime',
localField: 'code',
foreignField: 'code',
as: 'timelist',
}).sample({
size: 2
}).sort({
createdtime: 1
}).end().then(res2 => console.log(res2))
.catch(err => console.error(err))
查询代码是这样的