<commit_before>'use strict';

module.exports = function (grunt) {
  return grunt.registerTask('mongo-drop', 'Drop mongodb database.', function () {

    var options,
      mongoose = require('mongoose'),
      done = this.async(),
      db;

    options = this.options(
      {
        databases: [{
          dbname: null,
          host: 'localhost'
        }]
      });

    grunt.verbose.writeflags(options, 'Options');

    for (var i = 0; i < options.databases.length; i++) {

      if (options.databases[i].dbname !== null) {

        grunt.verbose.writeln('dropping: ' + options.databases[i].dbname);

        var connection = mongoose.createConnection('mongodb://' + options.databases[i].host + '/' + options.databases[i].dbname, function (err) {
          if (err) {
            grunt.log.writeln('Could not connect to mongodb, check if mongo is running');
            done(err);
          } else {
            grunt.log.writeln('Open db connection');
            connection.db.dropDatabase(function (err) {
              if (err) {
                grunt.log.writeln('Could not drop database');
                done(err);
              } else {
                grunt.log.writeln('Database dropped');
                done();
              }
            });
          }
        });
      }
    }
  });
};<commit_msg>only finish the task when all databases have been dropped<commit_after>'use strict';

module.exports = function (grunt) {
  return grunt.registerTask('mongo-drop', 'Drop mongodb database.', function () {

    var options,
      mongoose = require('mongoose'),
      done = this.async(),
      db;

    options = this.options(
      {
        databases: [{
          dbname: null,
          host: 'localhost'
        }]
      });

    grunt.verbose.writeflags(options, 'Options');

    var closedCount = 0;
    for (var i = 0; i < options.databases.length; i++) {

      if (options.databases[i].dbname !== null) {

        grunt.verbose.writeln('dropping: ' + options.databases[i].dbname);

        var connection = mongoose.createConnection('mongodb://' + options.databases[i].host + '/' + options.databases[i].dbname, function (err) {
          if (err) {
            grunt.log.writeln('Could not connect to mongodb, check if mongo is running');
            done(err);
          } else {
            grunt.log.writeln('Open db connection');
            connection.db.dropDatabase(function (err) {
              if (err) {
                grunt.log.writeln('Could not drop database');
                done(err);
              } else {
                grunt.log.writeln('Database dropped');
                
                ++closedCount;
                if (closedCount === options.databases.length) {
                    done();
                }
              }
            });
          }
        });
      }
    }
  });
};
{'fraction_non_alphanumeric': 0.1388986320589267, 'fraction_numerical': 0.001052262364082778, 'mean_word_length': 1.7110266159695817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5413957', 'n_tokens_mistral': 829, 'n_tokens_neox': 797, 'n_words': 168}