<commit_before>const
	expression = require("../expression.js"),
	extend = require("extend"),
	MongoClient = require("mongodb").MongoClient;

const nofn = entry=>entry;
const DEF_CONF = {
	url : "mongodb://localhost:27017/test",
	collection : "syslog"
}

class MongoTransport {
	constructor(config) {
		this.config = extend({},DEF_CONF,config);
		this.msg = config.format? expression.expr(JSON.stringify(config.format)) : nofn;
		this.mongo = MongoClient.connect(this.config.url);
		this.cn = this.config.collection;

		this.mongo.then(()=>{},err=>{
			console.error("Cannot stablish connection to mongo");
		});
	}
	transport(entry,callback) {
		this.mongo.then(db=>{
			db.collection(this.cn).insert(entry,(err,res)=>{
				callback(err,entry);
			});
		},err=>{<commit_msg>mongo transport<commit_after>const
	expression = require("../expression.js"),
	extend = require("extend"),
	MongoClient = require("mongodb").MongoClient;

const nofn = entry=>entry;
const DEF_CONF = {
	url : "mongodb://localhost:27017/test",
	collection : "syslog",
	interval : 1000,
	batch : 100
}

class MongoTransport {
	constructor(config) {
		this.config = extend({},DEF_CONF,config);
		this.msg = config.format? expression.expr(JSON.stringify(config.format)) : nofn;
		this.mongo = MongoClient.connect(this.config.url);
		this.cn = this.config.collection;
		this.buffer = [];

		this.mongo.then(
			db=>this.init(db),
			err=>{
				console.error("Cannot stablish connection to mongo");
			}
		)
	}

	init(db) {
		var cfg = this.config, buffer = this.buffer;

		this.ival = setInterval(()=>{
			while(buffer.length) {
				var arr = buffer.splice(0,cfg.batch);
				db.collection(this.cn).insert(arr,(err,res)=>{
					if(err) console.error(err);
				});
			}
		},cfg.interval);
	}

	transport(entry,callback) {
		this.mongo.then(db=>{
			buffer.unshift(entry);
			callback(null,entry);
		},err=>{
{'fraction_non_alphanumeric': 0.1793913507741591, 'fraction_numerical': 0.009610250934329953, 'mean_word_length': 4.369627507163324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4004699', 'n_tokens_mistral': 733, 'n_tokens_neox': 647, 'n_words': 103}