本文整理汇总了C#中MongoCollection.InsertBatch方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.InsertBatch方法的具体用法?C# MongoCollection.InsertBatch怎么用?C# MongoCollection.InsertBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.InsertBatch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
private static void Create(MongoCollection<Log> logs)
{
logs.InsertBatch(CreateSampleLogs(10));
logs.Insert(new Log("Some logs added", DateTime.Now));
Console.WriteLine("CREATE");
logs.FindAll().Print();
}
示例2: CreateAndInsertMultipleDocumentIntoCollection
/// <summary>
/// Demo inserting multiple document into collection.
/// </summary>
/// <param name="orders">The orders.</param>
private static void CreateAndInsertMultipleDocumentIntoCollection(MongoCollection<Order> orders)
{
Console.WriteLine("\n\n======= Insert Multiple Documents =======");
Console.WriteLine(string.Format("Document Count Before Insert: [ {0} ]", orders.Count()));
// Create new orders.
var order1 = new Order
{
OrderAmount = 100.23,
CustomerName = "Bugs Bunny"
};
var order2 = new Order
{
OrderAmount = 0.01,
CustomerName = "Daffy Duck"
};
IEnumerable<Order> orderList = new List<Order> { order1, order2 };
// Insert an IEnumerable.
orders.InsertBatch(orderList);
Console.WriteLine(string.Format("Inserted: {0}", order1));
Console.WriteLine(string.Format("Inserted: {0}", order2));
Console.WriteLine(string.Format("Document Count After Insert: [ {0} ]", orders.Count()));
}
示例3: GenerateDefaultJobs
private static void GenerateDefaultJobs(MongoCollection jobsCollection)
{
jobsCollection.InsertBatch(new List<Job>
{
new Job {Name = "Commons Coordinator"},
new Job {Name = "Sound & Light"},
new Job {Name = "Greeters"},
new Job {Name = "YRE Family Greeter"}
});
}
示例4: Seed
private static void Seed(MongoCollection<Message> collection, MongoCollection<User> users)
{
collection.InsertBatch(new List<Message>
{
new Message
{
Text = "chatim chatim",
Time = DateTime.Now,
UserName = "Pesho"
},
new Message
{
Text = "Mnogo chatim",
Time = DateTime.Now,
UserName = "Gosho"
},
new Message
{
Text = "S pesho chatim",
Time = DateTime.Now,
UserName = "Pesho"
}
});
users.InsertBatch(new List<User>
{
new User
{
Username = "Pesho"
},
new User
{
Username = "Gosho"
}
});
}
示例5: SeedData
private void SeedData(MongoDatabase db)
{
if (db == null) throw new ArgumentNullException("db");
// Reset db
db.GetCollection("IDSequence").Drop();
_usersCol = db.GetCollection<MembershipAccount>(MembershipAccount.GetCollectionName());
_usersCol.Drop();
var salt = Crypto.GenerateSalt();
var user1 = new MembershipAccount("User1")
{
PasswordSalt = salt,
Password = Crypto.HashPassword("[email protected]" + salt),
IsConfirmed = false
};
var user2 = new MembershipAccount("NonLocalUser")
{
IsLocalAccount = false,
IsConfirmed = true
};
_usersCol.InsertBatch(new[] { user1, user2 });
var oAuthTokenCol = db.GetCollection<OAuthToken>(OAuthToken.GetCollectionName());
oAuthTokenCol.Drop();
oAuthTokenCol.Insert(new OAuthToken("Tok3n", "tok3nSecret"));
var oAuthMembershipCol = db.GetCollection<OAuthMembership>(OAuthMembership.GetCollectionName());
oAuthMembershipCol.Drop();
oAuthMembershipCol.Insert( new OAuthMembership("Test", "[email protected]", 1) );
Users = _usersCol.AsQueryable();
OAuthTokens = oAuthTokenCol.AsQueryable();
OAuthMemberships = oAuthMembershipCol.AsQueryable();
}
示例6: ListProcessor
private static async void ListProcessor(List<Site> sites, int taskID, int totalTasks, MongoCollection<Site> mongoCollection)
{
Console.WriteLine("Running Task {0} of {1}", taskID, totalTasks);
var tasks = sites.Select(site => ProcessSite(site, taskID)).ToList();
await Task.WhenAll(tasks);
mongoCollection.InsertBatch(tasks.Select(t => t.Result).ToList());
foreach (var task in tasks)
{
task.Result.Dispose();
task.Dispose();
}
}