Using findOne in a loop takes too long in Node.js

后端 未结 5 491
时光取名叫无心
时光取名叫无心 2020-12-12 07:35

I\'m using Node.js with MongoDB, I\'m also using Monk for db access. I have the below code :

console.time(\"start\");

collection.findOne({name: \"jason\"},         


        
5条回答
  •  [愿得一人]
    2020-12-12 08:26

    Answer to 1: Yes, it is because node is async. The part where it logs names is executed only when the first findOne returns, whereas the file was saved is executed straight away.

提交回复
热议问题