我正在运行一个使用aggregate打印大约300个结果的查询。
在robo3t/mongo shell中执行查询时,查询速度非常快,但在NodeJs中使用mongoose执行时,查询速度非常慢。
尝试查找答案,登录此link尝试设置DBQuery.shellBatchSize = 500000;,但b/w两次查询的差异仍在7-8秒左右
另外,今天更新了mongoose和mongodb版本到最新版本。
下面是查询:
db.getCollection('fixed_activities').aggregate([
{
$lookup: {
from: "city",
localField: "activity_city",
foreignField: "_id",
as: "activity_location"
}
},
{
$lookup: {
from: "rate_sheet_activity_prices",
localField: "_id",
foreignField: "act_id",
as: "rate_sheets"
}
},
{
$lookup: {
from: "organizations",
localField: "rate_sheets.rate_sheet_id",
foreignField: "rate_sheets.rate_sheet_id",
as: "org_id"
}
},
{
$lookup: {
from: "images",
localField: "activity_image",
foreignField: "_id",
as: "activity_image"
}
},
{ $match: { org_id: { $exists: true, $not: { $size: 0 } } } }
])发布于 2019-11-28 05:33:08
我也有同样的问题,我的解决方案是在nodejs中从mongoose切换到原生mongodb控制器。
https://mongodb.github.io/node-mongodb-native/3.3/installation-guide/installation-guide/
https://stackoverflow.com/questions/59065671
复制相似问题