/// <summary> /// Completely empties the collection by deleting the collection itself. /// While this is not exactly deleting a document, it can be considered /// as a way of cleaning up the data. /// </summary> /// <returns>true if collections was cleaned successfully</returns> public bool DropCollection() { try { _context.GetDatabase().DropCollection(typeof(TEntity).Name); return(true); } catch (Exception) { return(false); } }
public void Initialize(string connectionStringName, string databaseName) { if (!Initialized) { ConnectionStringName = connectionStringName; _context = _contextFactory.CreateContext <MongoContext>(ConnectionStringName); _context.Initialize(databaseName); _database = _context.GetDatabase(); _collection = _database.GetCollection <TMongoEntity>(CollectionName); Initialized = true; Logger.Debug("Repository initialized to : {0}", ConnectionStringName); } else { Logger.Warning("Repository already initialized, attempt ignored."); } }