本文整理汇总了C#中IMongoCollection.Update方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.Update方法的具体用法?C# IMongoCollection.Update怎么用?C# IMongoCollection.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoCollection
的用法示例。
在下文中一共展示了IMongoCollection.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateUsingAtomicIncrement
/// <summary>
/// Demoes Updates a single field using an atomic Increment ($inc) operator.
/// </summary>
/// <param name="orders">The orders.</param>
private static void UpdateUsingAtomicIncrement(IMongoCollection orders)
{
Console.WriteLine("\n\n======= Update Document using Increment =======");
var selector = new Document { { "CustomerName", "Daffy Duck" } };
Console.WriteLine("Before Update: " + orders.FindOne(selector));
// Add 2000 to order amount on document matching selector.
orders.Update( new Document {{"$inc", new Document {{"OrderAmount", 2000}} }}, selector );
Console.WriteLine("After Update: " + orders.FindOne(selector));
}
示例2: UpdateDocument
/// <summary>
/// Demo of Updating a document.
/// </summary>
/// <param name="orders">The orders.</param>
private static void UpdateDocument( IMongoCollection orders )
{
Console.WriteLine( "\n\n======= Update Documents =======" );
var selector = new Document {{"CustomerName", "Daffy Duck"}};
Document docToUpdate = orders.FindOne( selector );
Console.WriteLine( "Before Update: " + docToUpdate );
// I'm in the money!
docToUpdate["OrderAmount"] = 1000000.00;
// Update Daffy's account before Hasaan finds him.
orders.Update( docToUpdate );
Console.WriteLine( "After Update: " + orders.FindOne( selector ) );
}