How to use the stop event on server side when all files are uploaded in jQuery File Upload
<p>I am using jQuery File Upload on express.js with jquery-file-upload-middleware and mongoose with mongoDB.</p>

<p>I want to upload images of a galery. The Galery object contains an array of Image objects, such as</p>

<pre><code>var GalerySchema = new mongoose.Schema({
    images: [ImageSchema]
})
</code></pre>

<p>After each file has been uploaded asynchronously, I want to push it into the images array of my Galery object.</p>

<p>I tried to do the following server side:</p>

<pre><code>// Is called everytime an image is uploaded
upload.on('end', function(fileInfo, rew, res){
    // Get the galery
    db.Galery.findOne({_id: req.fields.galery_id}, function(err, galery){

        // Create new Image object instance
        var image = new db.Image({src: fileInfo.name});

        // Save, in order to create auto generated _id
        image.save(function(err){
            if(err) {console.log(err); return; }

            // Add to Images array of Galery object
            galery.images.push(image);

            // Save galery with added image
            galery.save(function(err){
                if(err) { console.log(err); return; }
            });
        })
    });
});
</code></pre>

<p>Doing that, I get a well known  <code>[VersionError: No matching document found.]</code>, that, to my current knowledge, is due to the simultaneous access of the same mongodb document, since the upload happens asynchronously.</p>

<p>So in order to deal with the asynchronous fashion of the problem, it would be great to wait for all the uploads to finish, and then to insert the images one by one into the mongodb i.e. using <code>async.parallel()</code>.</p>

<p>But how do I access the event of all uploads having been finished?</p>

<p>I know that browser side i can use the <a href="https://github.com/blueimp/jQuery-File-Upload/wiki/Options#stop" rel="nofollow">stop event</a>. But first this does not contain any data about the uploaded files. Also, I want to do it the server-side. </p>

<p>Is there something like </p>

<pre><code>upload.on('doneAll', function(allFilesInfo, req, res){...})?
</code></pre>