Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Promise from aggregate() and find() with MongoDB driver for NodeJS

I head and always read that MongoDB driver (>2.0) for NodeJS supports promises. But the only examples I find are with the connect() and findOne() functions. While it works for those and I can get promises, it doesn't with aggregate() nor with find(). I get that's because they might be returning cursors, but since there is promise support, where are those promises? There must be a way to work with them. A link, an example or simple explanation would be so welcome :)

Thank you, Jordy.

like image 348
TigrouMeow Avatar asked Dec 18 '22 03:12

TigrouMeow


1 Answers

Chain the result from find() or aggregate() to .toArray(). The documentation of toArray for the current mongodb nodejs driver is here.

like image 93
Rico Chen Avatar answered Dec 20 '22 18:12

Rico Chen