Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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

Problem

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?

Problem courtesy of: Shamoon

Solution

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.

Solution courtesy of: Ryan Olds

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

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

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×