使用Robt 查询毫秒级,在node里面使用mongoose却有10s

什么原因呢?

在Robo 3T里面使用的查询语句:0.043s就返回了

db.getCollection('reports').find({pass:true})

image.png

而在node里面通过Mongoose去查询却需要10-12s,语句:

model(collection_name).find({pass:true})
image.png

求大佬拯救一下,好让我拯救世界~~~

另外,索引是这样设置吧~

image.png

好吧,默认robo 是limit=50,于是加了这么多,也才0.083s

db.getCollection('reports').find({pass:true}).limit(100000)

然后在mongoose里面limit=50,也差不多0.048s

limit mongoose robo 3t
50 50ms 81ms
100 54ms 83ms
1000 231ms 85ms
10000 9941ms 84ms

所以结论是,不管robo怎么查询,都特么是以limit=50??

我进入shell里面去查询,看起来没什么问题吧?90ms,指的是 explain的时间吗?

"nReturned" : 10969,
"executionTimeMillis" : 96,
"totalKeysExamined" : 10969,
"totalDocsExamined" : 10969,

语句

db.reports.find({pass:true}).limit(10000).hint({pass:1}).explain('executionStats')
阅读 2.5k
1 个回答

试试加lean

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题