<commit_before>// setup database connection
var MongoClient = require('mongodb').MongoClient;
var user = process.env.MONGODB_USER || 'dummy';
var pass = process.env.MONGODB_PASSWORD || '<PASSWORD>';
var dbip = process.env.MONGODB_SERVICE_HOST || '127.0.0.1';
var dbport = process.env.MONGODB_SERVICE_PORT || 27017;
var url = 'mongodb://'+user+':'+pass+'@'+dbip+'/'+dbport+'/sampledb'
// uncomment to use without authentication
//var url = 'mongodb://'+dbip+'/'+dbport+'/sampledb'
console.log('attempting mongoDB connection to ' + url);
MongoClient.connect(url, function(err, db) {
   if (err) {
      console.log('unable to connect to mongo database -' + err);
   } else {
      console.log('connected to mongo database, creating some dummy data...');
      // stuff in dummy data
      db.createCollection('test1', {strict:false}, function(err, collection) {
         collection.insert({name:"name1",type:1}, function(err, records) { if (err) throw err;});
      });
      db.createCollection('test2', {strict:false}, function(err, collection) {
         collection.insert({name:"name",type:2}, function(err, records) { if (err) throw err;});
      });

      // setup webserver
      var express = require('express');
      var app = express();
      app.get('/', function(req, res) {
         res.send('Hello MongoDB');
      });
      app.get('/test1', function(req, res) {
         db.collection('test1').find().toArray(function(err, items){
            console.log(items);
            res.send('items in test 1: ' + items.length);
         });
      });
      app.get('/test2', function(req, res) {
         db.collection('test2').find().toArray(function(err, items){
            console.log(items);
            res.send('items in test 2: ' + items.length);
         });
      });
      app.get('/test3', function(req, res) {
         db.collection('test3').find().toArray(function(err, items){
            console.log(items);
            res.send('items in test 3: ' + items.length);
         });
      });
      // start listening for client connections
      var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
      var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
      app.listen(server_port, server_ip_address, function() {
         console.log("Listening on " + server_ip_address + ", server_port " + server_port)
      });
   }
});
<commit_msg>fixing so that even if mongoDB fails the webapp will run.<commit_after>// setup database connection
var MongoClient = require('mongodb').MongoClient;
var user = process.env.MONGODB_USER || 'dummy';
var pass = process.env.MONGODB_PASSWORD || '<PASSWORD>';
var dbip = process.env.MONGODB_SERVICE_HOST || '127.0.0.1';
var dbport = process.env.MONGODB_SERVICE_PORT || 27017;
var db = null;
var url = 'mongodb://'+user+':'+pass+'@'+dbip+'/'+dbport+'/sampledb'
// uncomment to use without authentication
//var url = 'mongodb://'+dbip+'/'+dbport+'/sampledb'

var initMongo = function(errcallback) {
   console.log('attempting mongoDB connection to ' + url);
   MongoClient.connect(url, function(err, mydb) {
      if (err) {
         console.log('unable to connect to mongo database -' + err);
         errcallback(err);
         return;
      } else {
         db = mydb;
         console.log('connected to mongo database, creating some dummy data...');
         // stuff in dummy data
         db.createCollection('test1', {strict:false}, function(err, collection) {
            collection.insert({name:"name1",type:1}, function(err, records) { if (err) throw err;});
         });
         db.createCollection('test2', {strict:false}, function(err, collection) {
            collection.insert({name:"name",type:2}, function(err, records) { if (err) throw err;});
         });
      }
   });
}

// setup webserver
var express = require('express');
var app = express();
app.get('/', function(req, res) {
   res.send('Hello MongoDB');
});
app.get('/test1', function(req, res) {
   db.collection('test1').find().toArray(function(err, items){
      console.log(items);
      res.send('items in test 1: ' + items.length);
   });
});
app.get('/test2', function(req, res) {
   db.collection('test2').find().toArray(function(err, items){
      console.log(items);
      res.send('items in test 2: ' + items.length);
   });
});
app.get('/test3', function(req, res) {
   db.collection('test3').find().toArray(function(err, items){
      console.log(items);
      res.send('items in test 3: ' + items.length);
   });
});

// setup MongoDB
initMongo(function(err){ console.log('Couldnt connent to mongoDB: ' +err); });

// start listening for client connections
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
app.listen(server_port, server_ip_address, function() {
   console.log("Listening on " + server_ip_address + ", server_port " + server_port)
});

{'fraction_non_alphanumeric': 0.1717254023222652, 'fraction_numerical': 0.014259523324506009, 'mean_word_length': 3.2844677137870857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3324897', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1550, 'n_words': 334}