本文整理汇总了C#中MongoDB.Driver.QueryDocument.ToBsonDocument方法的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument.ToBsonDocument方法的具体用法?C# QueryDocument.ToBsonDocument怎么用?C# QueryDocument.ToBsonDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.QueryDocument
的用法示例。
在下文中一共展示了QueryDocument.ToBsonDocument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: storeOrder
/// <summary>
/// This method stores a order.
/// </summary>
/// <param name="o">The order object to store</param>
/// <returns>Success/Failure</returns>
public Boolean storeOrder(Order o)
{
dLog.Info("Entering method storeOrder | ID: " + o.id);
Boolean result = false;
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", o.id);
dLog.Debug("Finding if order exists");
BsonDocument myDoc = coll.FindOne(query);
query.Add("isComplete", o.isComplete);
query.Add("isSubmitted", o.isSubmitted);
query.Add("orderDate", o.orderDate);
query.Add("totalCost", o.totalCost.ToString());
//ensure we were passed a valid object before attempting to write
if (myDoc == null)
{
dLog.Debug("Inserting order");
coll.Insert(query);
result = true;
}
else
{
var update = new UpdateDocument();
update.Add(query.ToBsonDocument());
dLog.Debug("Updating order");
dLog.Debug("myDoc: " + myDoc.ToString());
dLog.Debug("update Query: " + update.ToString());
SafeModeResult wr = coll.Update(new QueryDocument("id", o.id), update, SafeMode.True);
dLog.Debug("SafeModeResult: " + wr.Ok);
if (wr.LastErrorMessage == null && wr.Ok)
{
result = true;
}
else
{
dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
}
}
//now insert the burritos
if (result)
{
dLog.Debug("Trying to insert " + o.burritos.Count + " burritos");
var index = 0;
foreach (Burrito b in o.burritos)
{
b.orderID = o.id;
dLog.Debug("Set order ID " + o.id + " for burrito: " + index);
if (b.validate())
{
dLog.Debug("Storing burrito: " + index);
result = burritoSvc.storeBurrito(b);
}
index++;
}
}
}
}
catch (Exception e2)
{
dLog.Error("Exception in storeBurrito: " + e2.Message);
}
finally
{
//using statement above already calls RequestDone()
}
return result;
}
示例2: storeBurrito
/// <summary>
/// This method stores a burrito.
/// </summary>
/// <param name="b">The burrito object to store</param>
/// <returns>Success/Failure</returns>
public Boolean storeBurrito(Burrito b)
{
dLog.Info("Entering method storeBurrito | ID: " + b.id);
Boolean result = false;
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("burrito");
var query = new QueryDocument("id", b.id);
dLog.Debug("Finding if burrito exists");
BsonDocument myDoc = coll.FindOne(query);
query.Add("beef", b.Beef);
query.Add("blackBeans", b.BlackBeans);
query.Add("brownRice", b.BrownRice);
query.Add("chicken", b.Chicken);
query.Add("chiliTortilla", b.ChiliTortilla);
query.Add("cucumber", b.Cucumber);
query.Add("flourTortilla", b.FlourTortilla);
query.Add("guacamole", b.Guacamole);
query.Add("herbGarlicTortilla", b.HerbGarlicTortilla);
query.Add("hummus", b.Hummus);
query.Add("jalapenoCheddarTortilla", b.JalapenoCheddarTortilla);
query.Add("jalapenos", b.Jalapenos);
query.Add("lettuce", b.Lettuce);
query.Add("onion", b.Onion);
query.Add("orderID", b.orderID);
query.Add("pintoBeans", b.PintoBeans);
query.Add("price", b.Price.ToString());
query.Add("salsaPico", b.SalsaPico);
query.Add("salsaSpecial", b.SalsaSpecial);
query.Add("salsaVerde", b.SalsaVerde);
query.Add("tomatoBasilTortilla", b.TomatoBasilTortilla);
query.Add("tomatoes", b.Tomatoes);
query.Add("wheatTortilla", b.WheatTortilla);
query.Add("whiteRice", b.WhiteRice);
//ensure we were passed a valid object before attempting to write
if (myDoc == null)
{
dLog.Debug("Inserting burrito");
coll.Insert(query);
result = true;
}
else
{
var update = new UpdateDocument();
update.Add(query.ToBsonDocument());
dLog.Debug("Updating burrito");
dLog.Debug("myDoc: " + myDoc.ToString());
dLog.Debug("update Query: " + update.ToString());
SafeModeResult wr = coll.Update(new QueryDocument("id", b.id), update, SafeMode.True);
dLog.Debug("SafeModeResult: " + wr.Ok);
if (wr.LastErrorMessage == null && wr.Ok)
{
result = true;
}
else
{
dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
}
}
}
}
catch (Exception e2)
{
dLog.Error("Exception in storeBurrito: " + e2.Message);
}
finally
{
//using statement above already calls RequestDone()
}
return result;
}
示例3: storeUser
/// <summary>
/// This method stores a user.
/// </summary>
/// <param name="u">The user object to store</param>
/// <returns>Success/Failure</returns>
public Boolean storeUser(User u)
{
dLog.Info("Entering method storeUser | ID: " + u.id);
Boolean result = false;
try
{
MongoServer server = MongoServer.Create();
//MongoCredentials credentials = new MongoCredentials("username", "password");
MongoDatabase db = server.GetDatabase("neatoBurrito");
//MongoDatabase db = server.GetDatabase("neatoBurrito", credentials);
using (server.RequestStart(db))
{
MongoCollection<BsonDocument> coll = db.GetCollection("user");
var query = new QueryDocument("id", u.id);
dLog.Debug("Finding if user exists");
BsonDocument myDoc = coll.FindOne(query);
query.Add("username", u.userName);
query.Add("password", u.password);
//ensure we were passed a valid object before attempting to write
if (myDoc == null)
{
dLog.Debug("Inserting user");
coll.Insert(query);
result = true;
}
else
{
var update = new UpdateDocument();
update.Add(query.ToBsonDocument());
dLog.Debug("Updating user");
dLog.Debug("myDoc: " + myDoc.ToString());
dLog.Debug("update Query: " + update.ToString());
SafeModeResult wr = coll.Update(new QueryDocument("id", u.id), update, SafeMode.True);
dLog.Debug("SafeModeResult: " + wr.Ok);
if (wr.LastErrorMessage == null && wr.Ok)
{
result = true;
}
else
{
dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
}
}
}
}
catch (Exception e2)
{
dLog.Error("Exception in storeEUser: " + e2.Message);
}
finally
{
//using statement above already calls RequestDone()
}
return result;
}