public void GenerateData(MongoDatabase db, IRandomGenerator random, int count) { int? customId = 0; string name; string position; List<MongoPilot> mongoPilots = new List<MongoPilot>(); for (int i = 1; i <= count; i++) { customId = i % 4 == 0 ? 0 : i; name = random.GetRandomString(random.GetRandomNumber(5, 50)); position = random.GetRandomString(random.GetRandomNumber(5, 50)); var pilot = new MongoPilot(customId, name, position); mongoPilots.Add(pilot); } MongoCollection<MongoPilot> pilots = db.GetCollection<MongoPilot>("Pilots"); pilots.InsertBatch(mongoPilots); }
private static void MondoDbDemo() { var context = new MongoContextProvider(); var dbName = "MongoShipyard"; context.Connect(dbName); var db = context.Database; // Drop the old DB collection and create a new one, for testing purposes :) db.DropCollection("Pilots"); var samplePilot = new MongoPilot(158, "Pesho", "Super-Admiral"); /* Mongo autogens the primary keys :)*/ MongoCollection<MongoPilot> pilots = db.GetCollection<MongoPilot>("Pilots"); pilots.Insert(samplePilot); // .InsertBatch for entire collections :) }