public static void DropCollection(this IMongoDatabase database, string collectionName) { if (database.CollectionExists(collectionName)) { database.DropCollection(collectionName); } }
public static bool CreateWorldTable(this MongoDatabase db) { // only create table if it does not already exist if (db.CollectionExists("World")) return true; try { // populate the table var worlds = new List<World>(10000); Parallel.For(0, 10000, i => { lock (worlds) { worlds.Add(new World() { id = i, randomNumber = SafeRandom.Instance.Next(0, 10000) + 1 }); } }); // insert new records into database var collection = db.GetCollection<World>("World"); collection.InsertBatch(worlds); return true; } catch { return false; } }