Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:25:44+00:00 2026-06-02T08:25:44+00:00

At the moment I use save to add a single document. Suppose I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:25:45+00:00Added an answer on June 2, 2026 at 8:25 am

    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:

    var total = docArray.length
      , result = []
    ;
    
    function saveAll(){
      var doc = docArray.pop();
    
      doc.save(function(err, saved){
        if (err) throw err;//handle error
    
        result.push(saved[0]);
    
        if (--total) saveAll();
        else // all saved here
      })
    }
    
    saveAll();
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application use NHibernate. I Have object A that contains set of objects B. I
I have two nested loop in XSL like this, at this moment I use
At the moment when i use this, i have to re-launch the app to
So right now I'm bashing my head - at the moment we use an
I need to decide which configuration framework to use. At the moment I am
I'm using jRuby at the moment (version 1.6.5) on my local machine. rvm use
Our company builds custom Java EE web solutions. At the moment, we use standard
At the moment I have a jQuery do a POST to a Controller which
I have an Activity which lets the user input names and the save them.
I'm doing a Microsoft Surface Application and I have this problem: I use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.