Watch keynotes and sessions from, our virtual developer conference.

Difference between profiler millis and toArray timing in JS

Can anyone explain why for a find query the profiler reports 30 ms in the millis fields, while the toArray in the node code takes 600+ ms?
It’s just one line with await and toArray wrapped with console.time.

I should mention that in the system.profile collection, after the profiler report, there’s another report with “getMore”, but it also takes ~30 ms, so together they account for 10% of the time reported in the JS code.

Hi Ivan,

I’m assuming you’re talking about the Node driver.

The difference is because the result of find() is an unexecuted cursor, which you can then string together with other operations like sort(), limit(), etc.

In contrast, toArray() actually executes the cursor, walk through all the output documents, and puts them all into an array.

If you execute the cursor after find() by iterating through it with, you should see a similar timing with toArray().

Best regards,