MongoDB NodeJS Native Driver(mongodb) vs Mongo Shell 性能 [英] MongoDB NodeJS Native Driver(mongodb) vs Mongo Shell Performance
问题描述
我在 MongoDB 的 table1 中有 10000 条记录.
I have 10000 records in MongoDB in table1.
数据如下:
"_id" : ObjectId("5d5e500cb89312272cfe51fc"),
"cities" : [
{
"cityid" : "5d5d2205cdd42d1cf0a92b33",
"value" : "XYZ"
},
{
"cityid" : "5d5d2214cdd42d1cf0a92b34",
"value" : "Rowcliffe"
},
],
查询如下:
{
$unwind: "$cities"
},
{ "$addFields": { "cities.cityid": { "$toObjectId": "$cities.cityid" } } },
{
$lookup: {
from: "cities",
localField: "cities.cityid",
foreignField: "_id",
as: "docs"
}
},
所以,在这里我在另一个表中查找 cityid,并在 Robo3T 和 mongo shell 中使用查找查询.一切正常.
So, here i lookup cityid in another table with lookup query in Robo3T and mongo shell. All works fine.
我在 0.08 秒 内获得了 10000 条记录的结果.
I am getting result in 0.08 sec for 10000 records.
现在,相同的查询 m 在 nodejs 和 mongodb 原生驱动中运行,这里 m 在 15 秒内得到结果.
Now, same query m running in nodejs with mongodb native driver, here m getting result in 15 sec.
我不明白为什么会有这么大的差异.我不知道我在 nodejs 中做错了什么.我在 nodejs 中使用 mongodb 本机驱动程序编写了相同的查询.
I'm not getting why this huge difference between this.I don't know what i am doing wrong in nodejs.I have written the same query in nodejs with mongodb native driver.
请让我知道我做错了什么.
Please let me know what i m doing wrong.
为什么这个nodejs mongodb原生驱动性能这么差?
Why this nodejs mongodb native driver performance is so poor?
推荐答案
在 Robo3T 中,有一个默认的查询限制,所以它需要更少的时间,因为当它获取限制时它会退出.
In Robo3T there is a default query limit so it takes less time because when it fetches the limit its exit.
为避免这种情况,您需要将此剪断添加到查询执行中:
To avoid it you need to add to your query execution this snipped:
// change the limit size, default 50
DBQuery.shellBatchSize = 500000;
这篇关于MongoDB NodeJS Native Driver(mongodb) vs Mongo Shell 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!