At the moment I use save to add a single document. Suppose I have an array of documents that I wish to store as single objects. Is there a way of adding them all with a single function call and then getting a single callback when it is done? I could add all the documents individually but managing the callbacks to work out when everything is done would be problematic.
Share
Mongoose doesn’t have bulk inserts implemented yet (see issue #723).
Since you know the number of documents you’re saving, you could write something like this:
This, of course, is a stop-gap solution and I would recommend using some kind of flow-control library (I use q and it’s awesome).