<commit_before>from pymongo import Connection

# While it may be more 'correct' to import app.config,
# I prefer this b/c it really doesn't have anything to do with Flask.
# This way it's that much easier to use in other Python projects.
import config

def connect():
    """Connect to the database and ensure indexes."""

    conn = Connection(config.DB_HOST, config.DB_PORT)
    db = conn[config.DATABASE]

    if hasattr(config, 'DB_USER') and hasattr(config, 'DB_PW'):
        db.authenticate(config.DB_USER, config.DB_PW)

    db.users.ensure_index('username', unique=True)
    return db<commit_msg>bug fix for when db has no user or password set<commit_after>from pymongo import Connection

# While it may be more 'correct' to import app.config,
# I prefer this b/c it really doesn't have anything to do with Flask.
# This way it's that much easier to use in other Python projects.
import config

def connect():
    """Connect to the database and ensure indexes."""

    conn = Connection(config.DB_HOST, config.DB_PORT)
    db = conn[config.DATABASE]

    if config.DB_USER and config.DB_PW:
        db.authenticate(config.DB_USER, config.DB_PW)

    db.users.ensure_index('username', unique=True)
    return db
{'fraction_non_alphanumeric': 0.09195402298850575, 'fraction_numerical': 0.0, 'mean_word_length': 3.856573705179283, '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': '2523752', 'n_tokens_mistral': 378, 'n_tokens_neox': 359, 'n_words': 139}