<commit_before>package databases


import (
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)


type MongoDB struct {
	Collection *mgo.Collection
	Session *mgo.Session
}


func (mongo *MongoDB) Init(config Config) {
	var err error
	mongo.Session, err = mgo.Dial(config.Addresses[0])  // TODO: use multiple addresses as connection pool
	if err != nil {
		panic(err)
	}
	mongo.Session.SetMode(mgo.Monotonic, true)
	mongo.Collection = mongo.Session.DB(config.Name).C(config.Table)
}


func (mongo *MongoDB) Shutdown() {
	mongo.Session.Close()
}


func (mongo *MongoDB) Create(key string, value map[string]interface{}) error {
	value["_id"] = key
	err := mongo.Collection.Insert(bson.M(value))
	return err
}


func (mongo *MongoDB) Read(key string) error {
	result := map[string]interface{}{}
	err := mongo.Collection.FindId(key).One(&result)
	return err
}

<commit_msg>implement connection pool in mongodb driver<commit_after>package databases


import (
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)


type MongoDB struct {
	Collection *mgo.Collection
	Session *mgo.Session
}


func (mongo *MongoDB) Init(config Config) {
	var err error
	var pool string = ""
	for _, address := range config.Addresses {
		pool += address + ","
	}
	mongo.Session, err = mgo.Dial(pool)
	if err != nil {
		panic(err)
	}
	mongo.Session.SetMode(mgo.Monotonic, true)
	mongo.Collection = mongo.Session.DB(config.Name).C(config.Table)
}


func (mongo *MongoDB) Shutdown() {
	mongo.Session.Close()
}


func (mongo *MongoDB) Create(key string, value map[string]interface{}) error {
	value["_id"] = key
	err := mongo.Collection.Insert(bson.M(value))
	return err
}


func (mongo *MongoDB) Read(key string) error {
	result := map[string]interface{}{}
	err := mongo.Collection.FindId(key).One(&result)
	return err
}


{'fraction_non_alphanumeric': 0.14646464646464646, 'fraction_numerical': 0.0028058361391694723, 'mean_word_length': 4.435975609756097, 'pattern_counts': {'":': 0, '<': 3, '<?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': '482483', 'n_tokens_mistral': 693, 'n_tokens_neox': 672, 'n_words': 145}