<commit_before>using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MongoDB.Driver;

namespace RapidCore.Mongo
{
    /// <summary>
    /// High-level connection to a MongoDB
    /// </summary>
    public class MongoDbConnection
    {
        private readonly IMongoDatabase mongoDb;

        public MongoDbConnection(IMongoDatabase mongoDb)
        {
            this.mongoDb = mongoDb;
        }

        /// <summary>
        /// Straight up first or default with filter
        /// </summary>
        /// <param name="collectionName">The collection to work on</param>
        /// <param name="filter">Filter expression</param>
        /// <returns>The document or default(TDocument)</returns>
        public virtual Task<TDocument> FirstOrDefaultAsync<TDocument>(string collectionName, Expression<Func<TDocument, bool>> filter)
        {
            return this.mongoDb
                .GetCollection<TDocument>(collectionName)
                .Find(filter)
                .FirstOrDefaultAsync();
        }

        /// <summary>
        /// Async insert
        /// </summary>
        /// <param name="collectionName">The collection to work on</param>
        /// <param name="doc">The document to insert</param>
        public virtual Task InsertAsync<TDocument>(string collectionName, TDocument doc)
        {<commit_msg>Make IMongoDatabase and IMongoClient available<commit_after>using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MongoDB.Driver;

namespace RapidCore.Mongo
{
    /// <summary>
    /// High-level connection to a MongoDB
    /// </summary>
    public class MongoDbConnection
    {
        private readonly IMongoDatabase mongoDb;

        public MongoDbConnection(IMongoDatabase mongoDb)
        {
            this.mongoDb = mongoDb;
        }
        
        /// <summary>
        /// Get the underlying database
        /// </summary>
        public virtual IMongoDatabase Database => mongoDb;
        
        /// <summary>
        /// Get the underlying client
        /// </summary>
        public virtual IMongoClient Client => mongoDb.Client;

        /// <summary>
        /// Straight up first or default with filter
        /// </summary>
        /// <param name="collectionName">The collection to work on</param>
        /// <param name="filter">Filter expression</param>
        /// <returns>The document or default(TDocument)</returns>
        public virtual Task<TDocument> FirstOrDefaultAsync<TDocument>(string collectionName, Expression<Func<TDocument, bool>> filter)
        {
            return this.mongoDb
                .GetCollection<TDocument>(collectionName)
                .Find(filter)
                .FirstOrDefaultAsync();
        }

        /// <summary>
        /// Async insert
        /// </summary>
        /// <param name="collectionName">The collection to work on</param>
        /// <param name="doc">The document to insert</param>
        public virtual Task InsertAsync<TDocument>(string collectionName, TDocument doc)
        {
{'fraction_non_alphanumeric': 0.11121794871794871, 'fraction_numerical': 0.0, 'mean_word_length': 2.1335341365461846, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, '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': '7555357', 'n_tokens_mistral': 793, 'n_tokens_neox': 774, 'n_words': 202}