【发布时间】:2020-04-20 06:37:47
【问题描述】:
我在循环中有这个查询:
const currentDatas = await Promise.all(nearestStations.map(async (ns: any) => {
return await this.stationCurrentDataRepo.findOne({
where: { stationId: parseInt(ns[0], 10) },
order: { date: 'DESC' },
});
}));
我想优化它以不进行数百次查询并在一次查询中获取数据。 我需要的是从 ids 数组($in ids 数组)中获取每个 stationId 的最新记录(按日期排序)。我需要所有找到的文档中的所有数据都符合我上面指定的要求。
【问题讨论】:
标签: javascript node.js mongodb typescript typeorm