<commit_before>// File name: setup.js
// Date: 03/04/2017
// Programmer: <NAME>
//
// Routes responsible for the setup of the test data in the Mongo database.

"use strict";
const config = require("../config");
const express = require("express");
const mongodb = require("mongodb");
const router = express.Router();

// Establish a mongo connection using settings from the config.js file
const mongoUri = "mongodb://" + config.db.host + "/" + config.db.name;
const mongoClient = mongodb.MongoClient;

// -------------------------------------------------------------
// Express Route Definitions
// -------------------------------------------------------------

// Route - Populate the database. If it already contains data clear it
//         before reloading.
//         http://localhost:3000/setup/populatedb
router.get('/populatedb', function(request, response, next) {
  console.log("Entered /populatedb...");
  const dbRecords = [{
      "account_no": 111111,
      "owner_fname": "John",
      "owner_mi": "Q",
      "owner_lname": "Public"
    },
    {
      "account_no": 111112,
      "owner_fname": "Jane",
      "owner_mi": "I",
      "owner_lname": "Thrify"
    },
    {
      "account_no": 111113,
      "owner_fname": "Roger",
      "owner_mi": "A",
      "owner_lname": "Johnsen"
    }
  ];
  mongoClient.connect(mongoUri)
    .then((db) => {
      console.log("Successfully connected to MongoDB");
      const collection = db.collection("accounts");
      const urlDocument = collection.count()
        .then((count) => {
          console.log("count: ", count);
          dbRecords.forEach((element) => {
            console.log("element to be inserted: ", element);
            collection.insert([element])
              .then((writeResult) => {
                response.json({
                  error: writeResult
                });
                response.send();
              })
              .catch((error) => {
                response.json({
                  error: "Error inserting URL in database. Error: " +
                    error
                });
                if (err) {
    return res.send();
}<commit_msg>added push of insert results onto new results array<commit_after>// File name: setup.js
// Date: 03/04/2017
// Programmer: <NAME>
//
// Routes responsible for the setup of the test data in the Mongo database.

"use strict";
const config = require("../config");
const express = require("express");
const mongodb = require("mongodb");
const router = express.Router();

// Establish a mongo connection using settings from the config.js file
const mongoUri = "mongodb://" + config.db.host + "/" + config.db.name;
const mongoClient = mongodb.MongoClient;

// -------------------------------------------------------------
// Express Route Definitions
// -------------------------------------------------------------

// Route - Populate the database. If it already contains data clear it
//         before reloading.
//         http://localhost:3000/setup/populatedb
router.get('/populatedb', function(request, response, next) {
  console.log("Entered /populatedb...");
  const dbRecords = [{
      "account_no": 111111,
      "owner_fname": "John",
      "owner_mi": "Q",
      "owner_lname": "Public"
    },
    {
      "account_no": 111112,
      "owner_fname": "Jane",
      "owner_mi": "I",
      "owner_lname": "Thrify"
    },
    {
      "account_no": 111113,
      "owner_fname": "Roger",
      "owner_mi": "A",
      "owner_lname": "Johnsen"
    }
  ];
  let results = [];
  mongoClient.connect(mongoUri)
    .then((db) => {
      console.log("Successfully connected to MongoDB");
      const collection = db.collection("accounts");
      const urlDocument = collection.count()
        .then((count) => {
          console.log("count: ", count);
          dbRecords.forEach((element) => {
            console.log("element to be inserted: ", element);
            collection.insert([element])
              .then((writeResult) => {
                /*
                response.json({
                  error: writeResult
                });
                */
                results.push(writeResult);
              })
              .catch((error) => {
                response.json({
                  error: "Error inserting URL in database. Error: " +
                    error
                });
{'fraction_non_alphanumeric': 0.19402298850574712, 'fraction_numerical': 0.013793103448275862, 'mean_word_length': 1.7399244332493702, 'pattern_counts': {'":': 24, '<': 5, '<?xml version=': 0, '>': 15, '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': '4775087', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1170, 'n_words': 292}