本文整理汇总了C#中MongoDB.Driver.QueryDocument.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument.Clear方法的具体用法?C# QueryDocument.Clear怎么用?C# QueryDocument.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.QueryDocument
的用法示例。
在下文中一共展示了QueryDocument.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getOrder
/// <summary>
/// This method retrieves a order.
/// </summary>
/// <param name="id">Unique ID of order to retrieve</param>
/// <returns>order object</returns>
public Order getOrder(Int32 id)
{
dLog.Info("Entering method getOrder | ID: " + id);
Order o = new Order();
try
{
MongoServer server = MongoServer.Create();
MongoDatabase db = server.GetDatabase("neatoBurrito");
//MongoCredentials credentials = new MongoCredentials("username", "password");
//MongoDatabase salaries = server.GetDatabase("salaries", credentials);
using (server.RequestStart(db))
{
MongoCollection<BsonDocument> coll = db.GetCollection("order");
var query = new QueryDocument("id", id);
BsonDocument myDoc = coll.FindOne(query);
//ensure we were passed a valid object before attempting to read
if (myDoc != null)
{
dLog.Debug("myDoc: " + myDoc.ToString());
#region Read Order Fields
o.id = id;
o.isComplete = myDoc["isComplete"].AsBoolean;
o.isSubmitted = myDoc["isSubmitted"].AsBoolean;
o.orderDate = myDoc["orderDate"].AsDateTime;
o.totalCost = Decimal.Parse(myDoc["totalCost"].AsString);
#endregion
//get burritos
dLog.Debug("Getting burritos");
coll = db.GetCollection("burrito");
query.Clear();
query.Add("orderID", id);
MongoCursor cur = coll.Find(query);
o.burritos = new List<Burrito>();
foreach (var doc in cur)
{
myDoc = (BsonDocument)doc;
Burrito b = new Burrito();
//cleaner but too many extra queries this way
//o.burritos.Add(burritoSvc.getBurrito(myDoc["id"].AsInt32));
#region Read burrito Fields
b.id = id;
b.Beef = myDoc["beef"].AsBoolean;
b.BlackBeans = myDoc["blackBeans"].AsBoolean;
b.BrownRice = myDoc["brownRice"].AsBoolean;
b.Chicken = myDoc["chicken"].AsBoolean;
b.ChiliTortilla = myDoc["chiliTortilla"].AsBoolean;
b.Cucumber = myDoc["cucumber"].AsBoolean;
b.FlourTortilla = myDoc["flourTortilla"].AsBoolean;
b.Guacamole = myDoc["guacamole"].AsBoolean;
b.HerbGarlicTortilla = myDoc["herbGarlicTortilla"].AsBoolean;
b.Hummus = myDoc["hummus"].AsBoolean;
b.JalapenoCheddarTortilla = myDoc["jalapenoCheddarTortilla"].AsBoolean;
b.Jalapenos = myDoc["jalapenos"].AsBoolean;
b.Lettuce = myDoc["lettuce"].AsBoolean;
b.Onion = myDoc["onion"].AsBoolean;
b.orderID = myDoc["orderID"].AsInt32;
b.PintoBeans = myDoc["pintoBeans"].AsBoolean;
b.Price = Decimal.Parse(myDoc["price"].AsString);
b.SalsaPico = myDoc["salsaPico"].AsBoolean;
b.SalsaSpecial = myDoc["salsaSpecial"].AsBoolean;
b.SalsaVerde = myDoc["salsaVerde"].AsBoolean;
b.TomatoBasilTortilla = myDoc["tomatoBasilTortilla"].AsBoolean;
b.Tomatoes = myDoc["tomatoes"].AsBoolean;
b.WheatTortilla = myDoc["wheatTortilla"].AsBoolean;
b.WhiteRice = myDoc["whiteRice"].AsBoolean;
#endregion
o.burritos.Add(b);
}
}
dLog.Debug("Finishing setting order");
}
}
catch (Exception e2)
{
dLog.Error("Exception in getOrder: " + e2.Message + "\n" + e2.StackTrace);
o = new Order();
}
finally
{
//using statement above already calls RequestDone()
}
return o;
}