开发者

How can I execute a callback after a massive multiple insert with Mongoose?

开发者 https://www.devze.com 2023-04-06 00:25 出处:网络
I have an object 开发者_运维问答results that\'s very large (maybe over 1,000 items). I\'m iterating over it to save to the DB but this seems very inefficient:

I have an object 开发者_运维问答results that's very large (maybe over 1,000 items). I'm iterating over it to save to the DB but this seems very inefficient:

        for result in results
          item = new Item result
          item.save()

Is there a more optimal way to do this and THEN get a callback as opposed to a callback for EVERY save?


The async module will help a lot with this. You're probably looking for a queue.

https://github.com/caolan/async#queue

You may be getting near the edge of a the normal Node.js use case.

0

精彩评论

暂无评论...
验证码 换一张
取 消