Why would I need two callback functions in a db.each() query?


#1

Question

Why would I need two callback functions in a db.each() query?

Answer

The reason db.each has the option of having two callback functions is that as a difference from db.get() and db.all(), db.each() runs the first callback for each result, and the second callback will be called once all the results have run through the first one. thus you can use the second callback to console log when it is done, or return a accumulated value created by the first callback.